bindiego
9/22/2015 - 9:38 AM

web beacon in node

web beacon in node

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 logging here
		
	} else { 
		res.writeHead(200, {'Content-Type': 'text/plain' });
		res.end('');
	}
}).listen(8888);