From fcc8e232dc94369341d5f7d377132f3b3062f4ae Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 23 Feb 2015 20:35:32 +0000 Subject: [PATCH] GET /favicon.ico should not load parent app --- lib/vhost-sni-server.js | 35 ++++++++++++++++++++++++++++++++--- package.json | 1 + public/favicon.ico | Bin 0 -> 198 bytes 3 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 public/favicon.ico diff --git a/lib/vhost-sni-server.js b/lib/vhost-sni-server.js index 0704caf..e88b7b0 100644 --- a/lib/vhost-sni-server.js +++ b/lib/vhost-sni-server.js @@ -6,6 +6,7 @@ module.exports.create = function (securePort, certsPath, vhostsdir) { var fs = require('fs'); var path = require('path'); var dummyCerts; + var serveFavicon; var secureContexts = {}; function loadDummyCerts() { @@ -98,9 +99,37 @@ module.exports.create = function (securePort, certsPath, vhostsdir) { 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." } }'); + 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, function (err2) { + res.writeHead(404); + res.end( + "" + + "" + + '' + + "" + + "" + + "Cannot " + + req.method + + " '" + + domaininfo.hostname + + '/' + + (domaininfo.pathname ? (domaininfo.pathname + '/') : '') + + req.url.replace(/^\//, '') + + "'" + + "" + + "" + ); + /* + res.end('{ "error": { "messages": "Route matched ' + + domaininfo.hostname + '/' + domaininfo.pathname + + ', but was not handled. Forcing hard stop to prevent fallthru." } }'); + */ + }); }); } try { diff --git a/package.json b/package.json index 1b55663..4b60f4c 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,7 @@ "nat-pmp": "0.0.3", "node-acme": "0.0.1", "request": "^2.53.0", + "serve-favicon": "^2.2.0", "serve-index": "^1.6.2", "serve-static": "^1.9.1", "ssl-root-cas": "^1.1.7", diff --git a/public/favicon.ico b/public/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..85a4d9fac03ba838f37feca9d583478bd4afd647 GIT binary patch literal 198 xcmZQzU<5(|0VXiLfq{WR42U&=SOAC>fEXkX0u5jillcGtKc*mwA|N9u!2sz^B%}ZU literal 0 HcmV?d00001