Is it possible to rewrite the URL path using node.js?(I\'m also using Express 3.0)
I\'ve tried something like this:
req.url = \'foo\';
A good idea should be to update the path too. My method suggestions:
app.use(function(req, res, next) {
console.log("request", req.originalUrl);
const removeOnRoutes = '/not-wanted-route-part';
req.originalUrl = req.originalUrl.replace(removeOnRoutes,'');
req.path = req.path.replace(removeOnRoutes,'');
return next();
});
By this way /not-wanted-route-part/users will became /users