From 669c69e5ebe1403346a95ee9885db523d5ee67fd Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Sat, 21 Feb 2015 18:00:39 +0000 Subject: [PATCH] disallow fallthru from one app to another --- lib/vhost-sni-server.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/vhost-sni-server.js b/lib/vhost-sni-server.js index 3be38ea..8f13323 100644 --- a/lib/vhost-sni-server.js +++ b/lib/vhost-sni-server.js @@ -79,13 +79,14 @@ module.exports.create = function (securePort, certsPath, vhostsdir) { return; } + console.log('[log] [once] Preparing mount for', domaininfo.hostname + '/' + domaininfo.dirpathname); domainMergeMap[domaininfo.hostname].mountsMap['/' + domaininfo.dirpathname] = function (req, res, next) { if (appContext) { appContext(req, res, next); return; } - console.log('[log] LOADING "' + domaininfo.hostname + '/' + domaininfo.pathname + '"'); + console.log('[log] LOADING "' + domaininfo.hostname + '/' + domaininfo.pathname + '"', req.url); getAppContext(domaininfo).then(function (localApp) { //if (localApp.arity >= 2) { /* connect uses .apply(null, arguments)*/ } if ('function' !== typeof localApp) { @@ -94,10 +95,18 @@ module.exports.create = function (securePort, certsPath, vhostsdir) { // Note: pathname should NEVER have a leading '/' on its own // we always add it explicitly + function localAppWrapped(req, res) { + console.log('[debug]', domaininfo.hostname + '/' + domaininfo.pathname, req.url); + localApp(req, res, function (err) { + res.end('{ "error": { "messages": "Route matched ' + + domaininfo.hostname + '/' + domaininfo.pathname + + ', but was not handled. Forcing hard stop to prevent fallthru." } }'); + }); + } try { - domainMergeMap[domaininfo.hostname].apps.use('/' + domaininfo.pathname, localApp); + domainMergeMap[domaininfo.hostname].apps.use('/' + domaininfo.pathname, localAppWrapped); console.info('Loaded ' + domaininfo.hostname + ':' + securePort + '/' + domaininfo.pathname); - appContext = localApp; + appContext = localAppWrapped; appContext(req, res, next); } catch(e) { console.error('[ERROR] ' + domaininfo.hostname + ':' + securePort + '/' + domaininfo.pathname); @@ -188,7 +197,7 @@ module.exports.create = function (securePort, certsPath, vhostsdir) { return; } - console.log('[log] [once] Loading mounts for ' + domainApp.hostname); + console.log('[log] [once] Loading all mounts for ' + domainApp.hostname); domainApp._loaded = true; app.use(vhost(domainApp.hostname, domainApp.apps)); app.use(vhost('www.' + domainApp.hostname, domainApp.apps));