I'm trying to do URL rewriting in Express JS 4. Everything I read says that I should be able to overwrite the request.url property in middleware. The two existing Node modules that do rewrite use this method. However, when I try to do this:
app.use('/foo', function(req, res){
var old_url = req.url;
req.url = '/bar';
console.log('foo: ' + old_url + ' -> ' + req.url);
});
app.get('/bar', function(req, res) {
console.log('bar: ' + req.url);
});
it just doesn't work.
One note that might help: it appears that req.url
above always is /
regardless of the actual URL used. Did Express 4 change how the URL is maintained, and not update their documentation? How do I accomplish URL rewriting in Express 4?