Skip to content

Instantly share code, notes, and snippets.

@codeorelse
Last active November 16, 2020 18:46
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 10 You must be signed in to fork a gist
  • Save codeorelse/604ff9de4e7e5c25f111 to your computer and use it in GitHub Desktop.
Save codeorelse/604ff9de4e7e5c25f111 to your computer and use it in GitHub Desktop.
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
Copy link

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

@J-prog-prog
Copy link

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
Copy link

flowcode

@J-prog-prog
Copy link

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