From ec3d5eb3de8db8853d248e8192961f5ca901bb2c Mon Sep 17 00:00:00 2001 From: Evilebot Tnawi Date: Tue, 14 May 2019 23:36:15 +0300 Subject: [PATCH] feat: support `HEAD` method by default (#398) --- README.md | 2 +- lib/middleware.js | 2 +- test/server.test.js | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1a785f7f8..e72f1b030 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/lib/middleware.js b/lib/middleware.js index 55d2bdea6..431322d91 100644 --- a/lib/middleware.js +++ b/lib/middleware.js @@ -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(); diff --git a/test/server.test.js b/test/server.test.js index 341cbcd57..e05ce94d6 100644 --- a/test/server.test.js +++ b/test/server.test.js @@ -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); + }); + it('POST request to bundle file', (done) => { request(app) .post('/public/bundle.js') @@ -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', () => {