Can't proxy to pow's domains #353

Closed
jingweno opened this Issue Dec 24, 2012 · 9 comments

Comments

Projects
None yet
4 participants

Hello,

I set up the following code with node-http-proxy to proxy the requests to a pow's domain http://foo.dev:

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

//// Http Proxy Server with Proxy Table
httpProxy.createServer({
  router: {
    'localhost': 'http://foo.dev'
  }
}).listen(8001);

But it redirects to pow's local home page http://localhost, instead of http://foo.dev. It looks like the domain name has been resolved to 127.0.0.1 before passing along.

Thanks,
Owen

To give you more context, I have a couple apps setup locally with pow and am on my way to build an API proxy. Say there are app1.foo.dev, app2.foo.dev and apis.foo.dev. I would want apis.foo.dev/app1 to route requests to app1 and so on for app2. Is it a good use case for node-http-proxy?

In production, I can totally see this approach works since node-http-proxy will bind to app's IP and each app will have its own IP on an individual machine. But in development with pow, I met the problem as I mentioned.

Owner

indexzero commented Dec 25, 2012

I have no idea how pow works so I have no idea why this wouldn't work. @sstephenson do you have any thoughts on why this wouldn't work? We transparently proxy headers, etc.

@indexzero I followed this example and it seemed to work after using proxy-by-url. I am trying to understand how proxy-by-url does it differently. Is setting the headers making it work?

Owner

indexzero commented Mar 9, 2013

I think this would work instead because localhost is resolved to 127.0.0.1:

//// Http Proxy Server with Proxy Table
httpProxy.createServer({
  router: {
    '127.0.0.1': 'http://foo.dev'
  }
}).listen(8001);

indexzero closed this Mar 9, 2013

jingweno commented Mar 9, 2013

@indexzero I tried 0.9.1 with the following:

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

//// Http Proxy Server with Proxy Table
httpProxy.createServer({
  pathnameOnly: true,
  router: {
    '/path': 'http://foo.dev'
  }
}).listen(8001);

curl with the following:

curl http://127.0.0.1:8001/path still routes to the home page of pow instead of foo.dev. As I mentioned earlier, I think the problem is due to the url and the host name are not set. With porxy-by-url, stuff works (https://github.com/dominictarr/proxy-by-url/blob/master/index.js#L49-L51).

Is this expected behaviour? Otherwise how can I help?

Cheers,
Owen

Did anyone figure this out. I just ran into the same problem trying to set up a proxy in an ember-cli application.

Owner

jcrugzz commented Aug 12, 2014

@mattbeedle this issue is not relevant to the current issue of http-proxy. Please checkover the readme as the api has change significantly.

@jcrugzz The api has changed, but I am still not able to proxy to a pow domain. I haven't looked into exactly what is causing the issue, but this seemed like a relevant place to post.

I also posted on stackoverflow, but haven't had a chance to look into whether or not it is cors yet. http://stackoverflow.com/questions/25205086/ember-cli-proxy-to-a-pow-server

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