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/"
我想要
P.S。:类似于" buildURL = url" ,可以在http-proxy
答案 0 :(得分:0)
我不确定您的具体操作,但请查看prependPath
和ignorePath
选项proxy.createProxysServer()
(https://github.com/nodejitsu/node-http-proxy#options)
更新:在代理对象上设置proxyReq
处理程序,您可以以任何方式操作路径。例如:
proxy.on('proxyReq', function(proxyReq, req, res, options) {
proxyReq.path = '/custom/path/here';
});