简体   繁体   中英

Heroku No such app error with Node.js node-http-proxy module

I'm trying to redirect traffic from my test app's /api/* url to my api hosted on Heroku.

Therefore, localhost/api/hello should be proxied to testapp.heroku.com/hello and the response returned.

Using node-http-proxy works perfectly on localhost to localhost, but when I point it to myapp.heroku.com, I get this error:

Heroku | No such app
There is no app configured at that hostname.
Perhaps the app owner has renamed it, or you mistyped the URL.

I have a feeling it's Heroku's routing system that's fudging up my proxied request, and I haven't found a way to fix it. Any ideas?

I have seen something similar when proxing requests to a different domain. The work around that I used was to modify the host header on the proxy request to match the domain name the remote site expects. So in your case the code would look like:

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


var server = httpProxy.createServer(function (req, res, proxy) {
  req.headers.host = 'myapp.heroku.com';
  proxy.proxyRequest(req, res, {
    port: 80,
    host: 'myapp.heroku.com'
  });
}).listen(9000);

I'd be interested to know if this works for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM