Skip to content

Commit

Permalink
feat: support HEAD method by default (#398)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi authored and hiroppy committed May 14, 2019
1 parent f227570 commit ec3d5eb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ _Note: The `publicPath` property is required, whereas all other options are opti
### methods

Type: `Array`
Default: `[ 'GET' ]`
Default: `[ 'GET', 'HEAD' ]`

This property allows a user to pass the list of HTTP request methods accepted by the server.

Expand Down
2 changes: 1 addition & 1 deletion lib/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module.exports = function wrapper(context) {
});
}

const acceptedMethods = context.options.methods || ['GET'];
const acceptedMethods = context.options.methods || ['GET', 'HEAD'];

if (acceptedMethods.indexOf(req.method) === -1) {
return goNext();
Expand Down
15 changes: 15 additions & 0 deletions test/server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ describe('Server', () => {
.expect(200, /console\.log\('Hey\.'\)/, done);
});

it('HEAD request to bundle file', (done) => {
request(app)
.head('/public/bundle.js')
.expect('Content-Type', 'application/javascript; charset=UTF-8')
.expect('Content-Length', '4631')
// eslint-disable-next-line no-undefined
.expect(200, undefined, done);

This comment has been minimized.

Copy link
@TrejGun

TrejGun May 15, 2019

you can pass void 0

});

it('POST request to bundle file', (done) => {
request(app)
.post('/public/bundle.js')
Expand Down Expand Up @@ -190,6 +199,12 @@ describe('Server', () => {
.get('/public/bundle.js')
.expect(404, done);
});

it("HEAD request to bundle file with methods set to ['POST']", (done) => {
request(app)
.get('/public/bundle.js')
.expect(404, done);
});
});

describe('no index mode', () => {
Expand Down

0 comments on commit ec3d5eb

Please # to comment.