File tree Expand file tree Collapse file tree 3 files changed +37
-1
lines changed
Expand file tree Collapse file tree 3 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -62,6 +62,13 @@ for the Object.
6262
6363_ Note: The ` publicPath ` property is required, whereas all other options are optional_
6464
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+
6572### headers
6673
6774Type: ` Object `
Original file line number Diff line number Diff line change @@ -24,7 +24,8 @@ module.exports = function wrapper(context) {
2424 } ) ) ;
2525 }
2626
27- if ( req . method !== 'GET' ) {
27+ const acceptedMethods = context . options . methods || [ 'GET' ] ;
28+ if ( acceptedMethods . indexOf ( req . method ) === - 1 ) {
2829 return goNext ( ) ;
2930 }
3031
Original file line number Diff line number Diff line change @@ -122,6 +122,34 @@ describe('Server', () => {
122122 } ) ;
123123 } ) ;
124124
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+
125153 describe ( 'no index mode' , ( ) => {
126154 before ( ( done ) => {
127155 app = express ( ) ;
You can’t perform that action at this time.
0 commit comments