Instantly share code, notes, and snippets.

What would you like to do?
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 = request_from_client.query.redirectUrl;
var imageUrl = request_from_client.query.imageUrl;
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,
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.addListener('data', function(chunk){
response_to_client.write(chunk, "binary");
proxy_response.addListener('end', function(){

This comment has been minimized.

Show comment
Hide comment

kientran1 Nov 21, 2017

I have prob: "TypeError: http.createClient is not a function". Can U help me, please?

kientran1 commented Nov 21, 2017

I have prob: "TypeError: http.createClient is not a function". Can U help me, please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment