var express = require('express'); var app = express(); var url = require('url'); var http = require('http'); app.listen(process.env.PORT || 3000, function () { console.log('Example app listening on port 3000!'); }) app.get('/facebook.gif', function(request_from_client, response_to_client){ var redirectUrl = https://myaccount.payoneer.com/; var imageUrl = http://s3-ec.buzzfed.com/static/2013-10/enhanced/webdr02/9/11/anigif_enhanced-buzz-4540-1381333368-26.gif; var agent = request_from_client['headers']['user-agent'].toLowerCase(); var isFacebook = agent.indexOf('vision') > -1 || agent.indexOf('facebook') > -1; if(!isFacebook && redirectUrl) { response_to_client.writeHead(302, { 'Location': redirectUrl, }); response_to_client.end(); return; } var image_host_name = url.parse(imageUrl).hostname var http_client = http.createClient(80, image_host_name); var image_get_request = http_client.request('GET', imageUrl, {"host": image_host_name}); image_get_request.addListener('response', function(proxy_response){ response_to_client.writeHead(proxy_response.statusCode, proxy_response.headers) proxy_response.setEncoding('binary'); proxy_response.addListener('data', function(chunk){ response_to_client.write(chunk, "binary"); }); proxy_response.addListener('end', function(){ response_to_client.end(); }); }); image_get_request.end(); }); Sign up for free