node-http-proxy icon indicating copy to clipboard operation
node-http-proxy copied to clipboard

Heroku - proxy server not working with browser

Open TelmoNeves opened this issue 10 years ago • 4 comments
trafficstars

I have the following code in my heroku app:

var http = require('http'),
httpProxy = require('http-proxy');

var proxy = httpProxy.createProxyServer({});

http.createServer(function(req, res) {
  proxy.web(req, res, {target:req.url, prependPath:false})
}).listen(process.env.PORT || 5000);

console.log("Server started on port "+process.env.PORT);

And then I'm trying to use this server along with a browser (e.g. Chrome) using appname.herokuapp.com:80 or using the port returned by console log function but only using the port 80 works yet it only says that the app doesn't exists when it does.

TelmoNeves avatar Jul 24 '15 22:07 TelmoNeves

When running in the Heroku environment, your app is already behind a proxy. The Heroku proxy is bound to appname.herokuapp.com:80, and forwards requests to your app dyno, which is bound to some randomly assigned port.

What exactly are you trying to do? Setting target to req.url seems quite odd.

keithmo avatar Jul 24 '15 22:07 keithmo

What I'm trying to do is to setup a caching proxy server like squid in heroku. Then I want to be able to use that proxy server on any browser like 111.222.333.444:80.

I don't know exactly what I'm doing since I never used nodejs but from what I can see, that piece of code makes a request from the url I'm trying to access, say google.com, and then returns the response to heroku and so to my browser right?

I'm aware that heroku already use a proxy yet I don't know how it works.

TelmoNeves avatar Jul 24 '15 22:07 TelmoNeves

Other people already questioned about this: https://github.com/nodejitsu/node-http-proxy/issues/301

TelmoNeves avatar Jul 25 '15 02:07 TelmoNeves

same here : (

neekey avatar Nov 25 '19 05:11 neekey