Skip to content

Commit ec3d5eb

Browse files
evilebottnawihiroppy
authored andcommitted
feat: support HEAD method by default (#398)
1 parent f227570 commit ec3d5eb

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ _Note: The `publicPath` property is required, whereas all other options are opti
7070
### methods
7171

7272
Type: `Array`
73-
Default: `[ 'GET' ]`
73+
Default: `[ 'GET', 'HEAD' ]`
7474

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

lib/middleware.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ module.exports = function wrapper(context) {
4444
});
4545
}
4646

47-
const acceptedMethods = context.options.methods || ['GET'];
47+
const acceptedMethods = context.options.methods || ['GET', 'HEAD'];
4848

4949
if (acceptedMethods.indexOf(req.method) === -1) {
5050
return goNext();

test/server.test.js

+15
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ describe('Server', () => {
9393
.expect(200, /console\.log\('Hey\.'\)/, done);
9494
});
9595

96+
it('HEAD request to bundle file', (done) => {
97+
request(app)
98+
.head('/public/bundle.js')
99+
.expect('Content-Type', 'application/javascript; charset=UTF-8')
100+
.expect('Content-Length', '4631')
101+
// eslint-disable-next-line no-undefined
102+
.expect(200, undefined, done);
103+
});
104+
96105
it('POST request to bundle file', (done) => {
97106
request(app)
98107
.post('/public/bundle.js')
@@ -190,6 +199,12 @@ describe('Server', () => {
190199
.get('/public/bundle.js')
191200
.expect(404, done);
192201
});
202+
203+
it("HEAD request to bundle file with methods set to ['POST']", (done) => {
204+
request(app)
205+
.get('/public/bundle.js')
206+
.expect(404, done);
207+
});
193208
});
194209

195210
describe('no index mode', () => {

0 commit comments

Comments
 (0)