Skip to content

Instantly share code, notes, and snippets.

@natos
Forked from kentbrew/favicon-interceptor.js
Created March 20, 2013 19:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save natos/5207746 to your computer and use it in GitHub Desktop.
Save natos/5207746 to your computer and use it in GitHub Desktop.
// early experiments with node had mysterious double requests
// turned out these were for the stoopid favicon
// here's how to short-circuit those requests
// and stop seeing 404 errors in your client console
var http = require('http');
http.createServer(function (q, r) {
// control for favicon
if (q.url === '/favicon.ico') {
r.writeHead(200, {'Content-Type': 'image/x-icon'} );
r.end();
console.log('favicon requested');
return;
}
// not the favicon? say hai
console.log('hello');
r.writeHead(200, {'Content-Type': 'text/plain'} );
r.write('Hello, world!');
r.end();
}).listen(8000);
console.log('Server running at http://127.0.0.1:8000/');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment