Proxy 具有多个代理的Ember CLI
问题: 我有一个Ember CLI应用程序,它将使用多个API,我需要在开发模式下代理这些API 背景: 我有一个遗留api,它公开了在本地开发机器上运行的Proxy 具有多个代理的Ember CLI,proxy,ember-cli,Proxy,Ember Cli,问题: 我有一个Ember CLI应用程序,它将使用多个API,我需要在开发模式下代理这些API 背景: 我有一个遗留api,它公开了在本地开发机器上运行的/api上的服务,该机器位于localhost:3000 我有一个新的api,它公开了/myapp/api/v1上的服务。这些服务最近从遗留应用程序中提取,并包含ember应用程序使用的大多数应用程序服务 ember应用程序在部署到子目录时使用的基本URL为/myapp 我使用ember-generate-httpproxy生成了两个http
/api
上的服务,该机器位于localhost:3000
我有一个新的api,它公开了/myapp/api/v1
上的服务。这些服务最近从遗留应用程序中提取,并包含ember应用程序使用的大多数应用程序服务
ember应用程序在部署到子目录时使用的基本URL为/myapp
我使用ember-generate-httpproxy
生成了两个http代理。它们位于/server/proxies/api.js
和server/proxies/myapp/api/v1.js
api.js
var proxyPath = '/api';
module.exports = function(app) {
var proxy = require('http-proxy').createProxyServer({});
proxy.on('error', function(err, req) {
console.error(err, req.url);
});
app.use(proxyPath, function(req, res, next){
// include root path in proxied request
req.url = proxyPath + '/' + req.url;
proxy.web(req, res, { target: 'http://localhost:3000' });
});
};
myapp/api/v1.js
var proxyPath = 'myapp/api/v1';
module.exports = function(app) {
var proxy = require('http-proxy').createProxyServer({});
proxy.on('error', function(err, req) {
console.error(err, req.url);
});
app.use(proxyPath, function(req, res, next){
req.url = proxyPath + '/' + req.url;
proxy.web(req, res, { target: 'http://localhost:4100' });
});
};
第一个代理to/api似乎正在工作,第二个api to/myapp/api/v1/whatever出现故障
它似乎没有被使用或考虑。例如,当我运行一个到myapp/api/v1/sessions的POST时,它只会说cannotpost。当我将调试器放在proxy.on和app.use函数上时,它们从未被命中
我哪里出了问题
var proxyPath = 'myapp/api/v1';
字符串开头缺少一个
/
。) 仅供参考,我没有发布赏金,因此将由@Asherlc来授予:)