Skip to content

Instantly share code, notes, and snippets.

@jameshartig
jameshartig / gist:762874
Created January 2, 2011 22:20
Get IP of user in node.js and CloudFlare-compatible
function getIP(req) {
var ip_address = (req.connection.remoteAddress ? req.connection.remoteAddress : req.remoteAddress);
//check for cloudflare
try {
if (req.headers['cf-connecting-ip']) {
var ipParts = ip_address.split(".");
var cloudFlare = false;
switch (parseInt(ipParts[0])) {
case 204:
//(204.93.177.0 - 204.93.177.255)
@kentbrew
kentbrew / favicon-interceptor.js
Created January 3, 2011 19:32
How to short-circuit those annoying favicon requests in node.js
// 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