better error handling

This commit is contained in:
AJ ONeal 2015-03-02 21:31:33 +00:00
parent fcc8e232dc
commit 3e026237bd
1 changed files with 27 additions and 0 deletions

View File

@ -99,6 +99,33 @@ module.exports.create = function (securePort, certsPath, vhostsdir) {
function localAppWrapped(req, res) { function localAppWrapped(req, res) {
console.log('[debug]', domaininfo.hostname + '/' + domaininfo.pathname, req.url); console.log('[debug]', domaininfo.hostname + '/' + domaininfo.pathname, req.url);
localApp(req, res, function (err) { localApp(req, res, function (err) {
if (err) {
console.error(err);
res.end(
"<html>"
+ "<head>"
+ '<link rel="icon" href="favicon.ico" />'
+ "</head>"
+ "<body>"
+ "<pre>"
+ "<code>"
+ "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(/</g, '&lt;')
+ "</code>"
+ "</pre>"
+ "</body>"
+ "</html>"
);
return;
}
if (!serveFavicon) { if (!serveFavicon) {
serveFavicon = require('serve-favicon')(path.join(__dirname, '..', 'public', 'favicon.ico')); serveFavicon = require('serve-favicon')(path.join(__dirname, '..', 'public', 'favicon.ico'));
} }