Skip to content

Instantly share code, notes, and snippets.

@ruturajv
Created April 25, 2012 04:28
Show Gist options
  • Save ruturajv/2486354 to your computer and use it in GitHub Desktop.
Save ruturajv/2486354 to your computer and use it in GitHub Desktop.
node.js web beacon (web bug) serving
http = require('http');
url = require('url');
http.createServer(function(req, res){
var requestURL = url.parse(req.url, true)['pathname'];
if (requestURL == '/log.gif') {
var imgHex = '47494638396101000100800000dbdfef00000021f90401000000002c00000000010001000002024401003b';
var imgBinary = new Buffer(imgHex, 'hex');
res.writeHead(200, {'Content-Type': 'image/gif' });
res.end(imgBinary, 'binary');
// Do MySQL/Redis/MongoDB logging
} else {
res.writeHead(200, {'Content-Type': 'text/plain' });
res.end('');
}
}).listen(8080); // Ofcourse u can use whatever IP/port combination you want
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment