File tree 3 files changed +37
-1
lines changed
3 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -62,6 +62,13 @@ for the Object.
62
62
63
63
_ Note: The ` publicPath ` property is required, whereas all other options are optional_
64
64
65
+ ### methods
66
+
67
+ Type: ` Array `
68
+ Default: ` [ 'GET' ] `
69
+
70
+ This property allows a user to pass the list of HTTP request methods accepted by the server.
71
+
65
72
### headers
66
73
67
74
Type: ` Object `
Original file line number Diff line number Diff line change @@ -24,7 +24,8 @@ module.exports = function wrapper(context) {
24
24
} ) ) ;
25
25
}
26
26
27
- if ( req . method !== 'GET' ) {
27
+ const acceptedMethods = context . options . methods || [ 'GET' ] ;
28
+ if ( acceptedMethods . indexOf ( req . method ) === - 1 ) {
28
29
return goNext ( ) ;
29
30
}
30
31
Original file line number Diff line number Diff line change @@ -122,6 +122,34 @@ describe('Server', () => {
122
122
} ) ;
123
123
} ) ;
124
124
125
+ describe ( 'accepted methods' , ( ) => {
126
+ before ( ( done ) => {
127
+ app = express ( ) ;
128
+ const compiler = webpack ( webpackConfig ) ;
129
+ instance = middleware ( compiler , {
130
+ stats : 'errors-only' ,
131
+ methods : [ 'POST' ] ,
132
+ logLevel,
133
+ publicPath : '/public/'
134
+ } ) ;
135
+ app . use ( instance ) ;
136
+ listen = listenShorthand ( done ) ;
137
+ } ) ;
138
+ after ( close ) ;
139
+
140
+ it ( 'POST request to bundle file with methods set to [\'POST\']' , ( done ) => {
141
+ request ( app ) . post ( '/public/bundle.js' )
142
+ . expect ( 'Content-Type' , 'application/javascript; charset=UTF-8' )
143
+ . expect ( 'Content-Length' , '3645' )
144
+ . expect ( 200 , / c o n s o l e \. l o g \( ' H e y \. ' \) / , done ) ;
145
+ } ) ;
146
+
147
+ it ( 'GET request to bundle file with methods set to [\'POST\']' , ( done ) => {
148
+ request ( app ) . get ( '/public/bundle.js' )
149
+ . expect ( 404 , done ) ;
150
+ } ) ;
151
+ } ) ;
152
+
125
153
describe ( 'no index mode' , ( ) => {
126
154
before ( ( done ) => {
127
155
app = express ( ) ;
You can’t perform that action at this time.
0 commit comments