GET /favicon.ico should not load parent app

This commit is contained in:
AJ ONeal 2015-02-23 20:35:32 +00:00
parent 045955b29e
commit fcc8e232dc
3 changed files with 33 additions and 3 deletions

View File

@ -6,6 +6,7 @@ module.exports.create = function (securePort, certsPath, vhostsdir) {
var fs = require('fs'); var fs = require('fs');
var path = require('path'); var path = require('path');
var dummyCerts; var dummyCerts;
var serveFavicon;
var secureContexts = {}; var secureContexts = {};
function loadDummyCerts() { function loadDummyCerts() {
@ -98,9 +99,37 @@ 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) {
res.end('{ "error": { "messages": "Route matched ' if (!serveFavicon) {
+ domaininfo.hostname + '/' + domaininfo.pathname serveFavicon = require('serve-favicon')(path.join(__dirname, '..', 'public', 'favicon.ico'));
+ ', but was not handled. Forcing hard stop to prevent fallthru." } }'); }
// 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(
"<html>"
+ "<head>"
+ '<link rel="icon" href="favicon.ico" />'
+ "</head>"
+ "<body>"
+ "Cannot "
+ req.method
+ " '"
+ domaininfo.hostname
+ '/'
+ (domaininfo.pathname ? (domaininfo.pathname + '/') : '')
+ req.url.replace(/^\//, '')
+ "'"
+ "</body>"
+ "</html>"
);
/*
res.end('{ "error": { "messages": "Route matched '
+ domaininfo.hostname + '/' + domaininfo.pathname
+ ', but was not handled. Forcing hard stop to prevent fallthru." } }');
*/
});
}); });
} }
try { try {

View File

@ -56,6 +56,7 @@
"nat-pmp": "0.0.3", "nat-pmp": "0.0.3",
"node-acme": "0.0.1", "node-acme": "0.0.1",
"request": "^2.53.0", "request": "^2.53.0",
"serve-favicon": "^2.2.0",
"serve-index": "^1.6.2", "serve-index": "^1.6.2",
"serve-static": "^1.9.1", "serve-static": "^1.9.1",
"ssl-root-cas": "^1.1.7", "ssl-root-cas": "^1.1.7",

BIN
public/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 198 B