diff --git a/lib/plugins/static.js b/lib/plugins/static.js index ef555632a..87b50cd29 100644 --- a/lib/plugins/static.js +++ b/lib/plugins/static.js @@ -89,9 +89,6 @@ function serveStatic(options) { assert.optionalString(opts.file, 'options.file'); assert.bool(opts.appendRequestPath, 'options.appendRequestPath'); - var p = path.normalize(opts.directory).replace(/\\/g, '/'); - var re = new RegExp('^' + escapeRE(p) + '/?.*'); - function serveFileFromStats(file, err, stats, isGzip, req, res, next) { if (typeof req.closed === 'function' && req.closed()) { next(false); @@ -186,6 +183,9 @@ function serveStatic(options) { } } + var p = path.normalize(file).replace(/\\/g, '/'); + var re = new RegExp('^' + escapeRE(p) + '/?.*'); + if (req.method !== 'GET' && req.method !== 'HEAD') { next(new MethodNotAllowedError('%s', req.method)); return;