Le_*_*sms 12 proxy heroku http-proxy node.js
我正在尝试将流量从我的测试应用程序的/ api/*url重定向到我在Heroku上托管的api.
因此,localhost/api/hello应该代理到testapp.heroku.com/hello并返回响应.
使用node-http-proxy在localhost上完美地工作到localhost,但当我将它指向myapp.heroku.com时,我收到此错误:
Heroku | No such app
There is no app configured at that hostname.
Perhaps the app owner has renamed it, or you mistyped the URL.
Run Code Online (Sandbox Code Playgroud)
我有一种感觉是Heroku的路由系统正在捏造我的代理请求,而我还没有找到解决方法.有任何想法吗?
小智 16
在将请求代理到其他域时,我看到了类似的东西.我使用的工作是修改代理请求上的主机头以匹配远程站点期望的域名.所以在你的情况下代码看起来像:
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);
Run Code Online (Sandbox Code Playgroud)
我很想知道这是否适合你.
归档时间: |
|
查看次数: |
3101 次 |
最近记录: |