我怎样才能看到/修改ember http-proxy命中的最终网址

时间:2015-09-18 06:16:52

标签: ember.js cors ember-cli http-proxy node-http-proxy

Http-Proxy,与适配器一样,添加" / store-name"在我指定的代理目标的最后一个。
我希望完全控制URL,或者至少我应该能够为URL添加后缀。

文件server/proxies/members.js对我来说就是这样。

var proxyPath = '/members';

module.exports = function(app) {
// For options, see:
// https://github.com/nodejitsu/node-http-proxy
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:8082/connection/testdb?tablename=' });
});
};

作为最终网址,这个案例看起来像是

  

" http://localhost:8082/connection/testdb?tablename=/members/"

我想要

  

http://localhost:8082/connection/testdb?tablename=storename

P.S。:类似于" buildURL = url" ,可以在http-proxy

1 个答案:

答案 0 :(得分:0)

我不确定您的具体操作,但请查看prependPathignorePath选项proxy.createProxysServer()https://github.com/nodejitsu/node-http-proxy#options

更新:在代理对象上设置proxyReq处理程序,您可以以任何方式操作路径。例如:

proxy.on('proxyReq', function(proxyReq, req, res, options) {
    proxyReq.path = '/custom/path/here';
});