0
votes

I am making ajax call to node server, i have a set of my request like this in front-end

$.ajax({
   url: '/getdata/call',
   dataType: 'json',
   method: 'get',
   contentType: 'application/json'
   ....
});

when I print the request url parameter in node server using express i got like this

app.use(function (req, res, next) {
     console.log(req.url); // /getdata/call
     next();
});

and everything is working fine, and i set a proxy in by browser settings with manual proxy configuration.

after that I am getting the request url like

app.use(function (req, res, next) {
         console.log(req.url); // http:192.168.192.10/getdata/call
         next();
});

ie, the full path of the request server , and because of that i cant resolve the request properly, i need an relative path for req.url always like '/getdata/**'

i tried to replace it like ,

app.use(function (req, res, next) {
     req.url = req.url.replace('wht is the ip','');
     next();
});

but req object is setting that in other props like originalUrl, and in some request path modifying the url is giving 404.

So is there any way to set the url in request header or proxy settings header etc. ? ajax header 'location, host' doesn't help.

1

1 Answers

0
votes

Use req.path instead of req.url.