From 0ae9e5a0697fd8283a8af3fc05ad3d989f3b7360 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 2 Mar 2015 22:42:14 +0000 Subject: [PATCH] fix error handling --- lib/vhost-sni-server.js | 70 ++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/lib/vhost-sni-server.js b/lib/vhost-sni-server.js index 06f396d..c9fec1d 100644 --- a/lib/vhost-sni-server.js +++ b/lib/vhost-sni-server.js @@ -28,41 +28,41 @@ module.exports.create = function (securePort, certsPath, vhostsdir) { return dummyCerts; } - function handleAppScopedError(fn) { - return function (req, res, next) { - next(function (err) { - if (!err) { - fn(req, res); - return; - } + function handleAppScopedError(req, res, fn) { + function next(err) { + if (!err) { + fn(req, res); + return; + } - console.error(err); - res.writeHead(500); - res.end( - "" - + "" - + '' - + "" - + "" - + "
"
-          + ""
-          + "Method: " + req.method
-          + '\n'
-          + "Hostname: " + domaininfo.hostname
-          + '\n'
-          + "App: " + (domaininfo.pathname ? (domaininfo.pathname + '/') : '')
-          + '\n'
-          + "Route: " + req.url//.replace(/^\//, '')
-          + '\n'
-            // TODO better sanatization
-          + 'Error: '  + (err.message || err.toString()).replace(/"
-          + "
" - + "" - + "" - ); - }); + console.error(err); + res.writeHead(500); + res.end( + "" + + "" + + '' + + "" + + "" + + "
"
+        + ""
+        + "Method: " + req.method
+        + '\n'
+        + "Hostname: " + domaininfo.hostname
+        + '\n'
+        + "App: " + (domaininfo.pathname ? (domaininfo.pathname + '/') : '')
+        + '\n'
+        + "Route: " + req.url//.replace(/^\//, '')
+        + '\n'
+          // TODO better sanatization
+        + 'Error: '  + (err.message || err.toString()).replace(/"
+        + "
" + + "" + + "" + ); } + + return next; } function createSecureContext(certs) { @@ -135,14 +135,14 @@ module.exports.create = function (securePort, certsPath, vhostsdir) { // we always add it explicitly function localAppWrapped(req, res) { console.log('[debug]', domaininfo.hostname + '/' + domaininfo.pathname, req.url); - localApp(req, res, handleAppScopedError(function () { + localApp(req, res, handleAppScopedError(req, res, function (req, res) { if (!serveFavicon) { serveFavicon = require('serve-favicon')(path.join(__dirname, '..', 'public', 'favicon.ico')); } // TODO redirect GET /favicon.ico to GET (req.headers.referer||'') + /favicon.ico // TODO other common root things - robots.txt, app-icon, etc - serveFavicon(req, res, handleAppScopedError(function () { + serveFavicon(req, res, handleAppScopedError(req, res, function (req, res) { res.writeHead(404); res.end( ""