From 85b6f4831da3b012fe48babfe95a4112155b6ccf Mon Sep 17 00:00:00 2001 From: Matthew Brill Date: Fri, 3 Aug 2018 15:18:54 -0700 Subject: [PATCH] fix NotAuthorized error when serving static files while directory variable is set to './ --- lib/plugins/static.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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;