問題:灰燼CLI與多代理
我有灰燼CLI應用程序會消耗多種API,這是我需要代理髮展模式。
背景:
我在我的/api
本地開發計算機上運行的傳統API暴露在服務localhost:3000
我有一個新的API,它在/myapp/api/v1
公開服務。這些服務最近從舊版應用程序中提取,幷包含了大部分應用程序服務使用的應用程序。
該燼應用程序使用baseURL /myapp
,因爲它正在部署到一個子目錄。
我使用ember generate http-proxy
生成了兩個http-proxys。它們分別位於/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 /任何失敗。
它似乎沒有被使用或考慮。當我運行時,例如POST到myapp/api/v1/sessions,它只是說不能POST。當我將調試器放在proxy.on和app.use函數上時,它們從未被擊中。
我在哪裏錯了?
僅供參考,我沒有貼獎金,因此這將是高達@Asherlc獎勵吧:) – DVG