Main app calls app.use('/mountpath', otherApp)
, then all redirects and locations in otherApp
must be prefixed with /mountpath
. As stated in documentation it's supposed to be supported right out of the box.
Extract from documentation:
This next redirect is relative to the mount point of the application. For example, if you have a blog application mounted at /blog, ideally it has no knowledge of where it was mounted. So, where a redirect of /admin/post/new would simply give you http://example.com/admin/post/new, the following mount-relative redirect would give you http://example.com/blog/admin/post/new:
res.redirect('admin/post/new');
app.use('/mountpath', otherApp);
otherApp.get('/url', function (req, res) {
res.redirect('otherUrl');
});
http://app/mountpath/url → Location: /mountpath/otherUrl
http://app/mountpath/url → Location: otherUrl
Run node server.js
and curl http://localhost:3002/mounted/hello
and see how you're redirected to world
instead of /mounted/world
.