Skip to content

Instantly share code, notes, and snippets.

Embed
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,
});
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();
});
@kientran1

This comment has been minimized.

Copy link

@kientran1 kientran1 commented Nov 21, 2017

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

@J-prog-prog

This comment has been minimized.

Copy link

@J-prog-prog J-prog-prog commented Nov 16, 2020

#(https://user-images.githubusercontent.com/72067685/99291614-26011800-2851-11eb-80df-ec128b2b76f6.png)

Hellow welcome to see pictures

@J-prog-prog

This comment has been minimized.

@J-prog-prog

This comment has been minimized.

Copy link

@J-prog-prog J-prog-prog commented Nov 16, 2020

flowcode

@J-prog-prog

This comment has been minimized.

Copy link

@J-prog-prog J-prog-prog commented Nov 16, 2020

https://modificationdispatch.com/mdm4fnua?key=5e8085cb9c0821e8184e8ae90b499748

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.