我正在对节点服务器进行ajax调用,我在前端有一组这样的请求
$.ajax({
url: '/getdata/call',
dataType: 'json',
method: 'get',
contentType: 'application/json'
....
});
当我使用express打印节点服务器中的request url
参数时我得到了这样的
app.use(function (req, res, next) {
console.log(req.url); // /getdata/call
next();
});
并且一切正常,我通过手动代理配置的浏览器设置设置代理。
之后我收到请求网址
app.use(function (req, res, next) {
console.log(req.url); // http:192.168.192.10/getdata/call
next();
});
即请求服务器的完整路径,由于我无法正确解析请求,我需要一个req.url
的相对路径,总是像'/getdata/**'
我试图将其替换为,
app.use(function (req, res, next) {
req.url = req.url.replace('wht is the ip','');
next();
});
但是req对象在其他道具中设置了originalUrl
,而在某些请求路径中修改url则给出404。
那么有没有办法在请求标题或代理设置标题等中设置网址?
ajax标头'location, host'
无效。
答案 0 :(得分:0)
使用req.path
代替req.url
。