问题:
我有一个Ember CLI应用程序,它将使用多个API,我需要在开发模式下代理这些API。
背景:
我有一个旧式api,它在/api上公开服务,运行在localhost:3000的本地开发机器上。
我有一个新的api,它在/myapp/api/v1上公开服务。这些服务是最近从遗留应用程序中提取出来的,包含了成员应用程序使用的大多数应用程序服务。
应用程序使用baseURL of /myapp,因为它正在被部署到一个子目录中。
我使用ember generate http-proxy生成了两个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' });
});
};第一个代理,即/api,似乎在工作,第二个API,到/myapp/api/v1/任何失败的api。
它似乎没有被使用或考虑。例如,当我运行到myapp/api/v1/会话的帖子时,它只是说不能发布。当我将调试器放在proxy.on和app.use函数上时,它们永远不会被击中。
我哪里出问题了?
发布于 2015-06-16 10:28:14
var proxyPath = 'myapp/api/v1';在字符串的开头缺少一个/ ;)
https://stackoverflow.com/questions/30267849
复制相似问题