fixed enclosure problem for static modules

This commit is contained in:
tigerbot 2017-10-25 18:06:41 -06:00
parent c4af0d05ec
commit c9318b65b0
1 changed files with 7 additions and 6 deletions

View File

@ -355,8 +355,9 @@ module.exports.create = function (deps, conf, greenlockMiddleware) {
var staticServer; var staticServer;
var staticHandlers = {}; var staticHandlers = {};
var indexHandlers = {}; var indexHandlers = {};
function serveStatic(modOpts, req, res) { function serveStatic(req, res) {
var rootDir = req.connection.rootDir; var rootDir = req.connection.rootDir;
var modOpts = req.connection.modOpts;
if (!staticHandlers[rootDir]) { if (!staticHandlers[rootDir]) {
staticHandlers[rootDir] = require('express').static(rootDir, { staticHandlers[rootDir] = require('express').static(rootDir, {
@ -391,14 +392,15 @@ module.exports.create = function (deps, conf, greenlockMiddleware) {
+ (modOpts.view||'') + (modOpts.view||'')
; ;
if (!modOpts.indexes || ('*' !== modOpts.indexes[0] && !modOpts.indexes.some(function (pathname) { function pathMatchesUrl(pathname) {
if (req.url === pathname) { if (req.url === pathname) {
return true; return true;
} }
if (0 === req.url.replace(/\/?$/, '/').indexOf(pathname.replace(/\/?$/, '/'))) { if (0 === req.url.replace(/\/?$/, '/').indexOf(pathname.replace(/\/?$/, '/'))) {
return true; return true;
} }
}))) { }
if (!modOpts.indexes || ('*' !== modOpts.indexes[0] && !modOpts.indexes.some(pathMatchesUrl))) {
doFinal(); doFinal();
return; return;
} }
@ -431,11 +433,10 @@ module.exports.create = function (deps, conf, greenlockMiddleware) {
} }
if (!staticServer) { if (!staticServer) {
staticServer = require('http').createServer(function (req, res) { staticServer = require('http').createServer(serveStatic);
serveStatic(modOpts, req, res);
});
} }
conn.rootDir = rootDir; conn.rootDir = rootDir;
conn.modOpts = modOpts;
return emitConnection(staticServer, conn, opts); return emitConnection(staticServer, conn, opts);
}) })
.catch(function (err) { .catch(function (err) {