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.
精彩评论