I am using nodejs, expressjs and request to create a reverse proxy.
What I want is that when a request is sent to http://localhost:PORT/NAME/ that the corresponding page is loaded.
For example, if I enter http://localhost:1234/google/ the google website would be loaded and if I enter http://localhost:1234/stack/ the stackoverflow page would be loaded instead.
I tried code similar to the one here
var request = require('request');
app.get('/google', function(req,res) {
//modify the url in any way you want
var newurl = 'http://google.com/';
request(newurl).pipe(res);
});
The problem is, that it loads the pages, but not completely, since the pages themselves wanna load images and css and stuff and make requests like /images/example.jpg And those obviously end with a 404 error.
Has anyone a handy solution for this problem? Especially since simply setting a route for /images would be no good, sinceI have two possible target servers and the proxy wouldn't know which would be the right one.
First of all, this is a forward proxy, second, here is a working code of what you want, modify it as you please
call this from
http://127.0.0.1:5432/yahoo.com