【问题标题】:how can i see/modify the final url that ember http-proxy hits我如何查看/修改 ember http-proxy 命中的最终 url
【发布时间】:2015-09-18 06:16:51
【问题描述】:

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=' });
});
};

由于最终的 url 是这种情况的样子

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

我想要

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

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

【问题讨论】:

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


    【解决方案1】:

    我不清楚您到底想做什么,但请查看 proxy.createProxysServer() (https://github.com/nodejitsu/node-http-proxy#options) 的 prependPathignorePath 选项

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

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

    【讨论】:

    • 当我们创建一个代理 url http://localhost:8080 并用 Em.store.findAll('member') 命中它时,现在如果你检查 url 传递的 url 是 http://localhost:8080/members/.因此 "/members/" 似乎默认添加我要问的是,我怎样才能将此网址更改为其他内容,例如:http://localhost:8080/member?tablename=table,即添加后缀甚至删除强制添加"/members/"。 ?
    猜你喜欢
    • 2019-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-28
    • 1970-01-01
    相关资源
    最近更新 更多