我下面http://blog.nodejitsu.com/http-proxy-intro/寫我的代理服務器來指向子域當我使用節點運行此文件到節點不同的端口子域使用HTTP代理不顯示節點上運行的應用程序
var http = require('http'),
httpProxy = require('http-proxy');
//
// Just set up your options...
//
var options = {
hostnameOnly: true,
router: {
'localhost': '127.0.0.1:80'
'sub.localhost': '127.0.0.1:9012',
}
}
//
// ...and then pass them in when you create your proxy.
//
var proxyServer = httpProxy.createServer(options).listen(80)
上運行的應用程序和嘗試訪問localhost
或sub.localhost
,我收到此錯誤。我真的不明白什麼是錯的。
Error: Must provide a proper URL as target
at ProxyServer.<anonymous> (D:\myProjects\bitbucket\temp\node_modules\http-proxy\lib\http-proxy\index.js:68:35)
at Server.closure (D:\myProjects\bitbucket\temp\node_modules\http-proxy\lib\http-proxy\index.js:125:43)
at emitTwo (events.js:87:13)
at Server.emit (events.js:172:7)
at HTTPParser.parserOnIncoming [as onIncoming] (_http_server.js:525:12)
at HTTPParser.parserOnHeadersComplete (_http_common.js:88:23)
看到http://stackoverflow.com/a/24108494無關的問題,但它有你需要的答案。 – Neilos