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