2011-06-22 33 views
10

我試圖將流量從我的測試應用程序的/ api/* url重定向到我在Heroku上託管的api。Heroku Node.js node-http-proxy模塊沒有這樣的應用程序錯誤

因此,應將localhost/api/hello 代理到testapp.heroku.com/hello 並返回響應。

使用節點-HTTP代理的作品完美地在本地主機到本地主機,但是當我將它指向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. 

我有一種感覺它的Heroku的路由系統的冒充我的代理請求,我還沒有找到解決的辦法。有任何想法嗎?

回答

15

當接近不同域的請求時,我看到類似的東西。我使用的工作是修改代理請求上的主機頭以匹配遠程站點所期望的域名。所以在你的情況下代碼將如下所示:

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); 

我很想知道這是否適合你。

+0

它的工作完美無瑕。設置標題中的主機修復了它。出於某種原因,我認爲http-proxy會做到這一點。感謝您使用一個骯髒的捲曲破解我!謝謝! –

+3

http-proxy支持一個changeOrigin選項來處理這個問題。 https://github.com/nodejitsu/node-http-proxy#http-proxy – 2012-10-27 03:38:07

+0

我從字面上發現並做了完全相同的事情。 –

相關問題