Skip to content

Commit

Permalink
fix(remountable-routes): bug with user routes remounting to itself
Browse files Browse the repository at this point in the history
  • Loading branch information
julianlam committed Feb 11, 2021
1 parent 9021f07 commit bc68e99
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,9 @@ async function addCoreRoutes(app, router, middleware) {
account: 'user',
};
await Promise.all(remountable.map(async (mount) => {
const original = mount;
mount = mountHash[mount] || mount;
const method = mount;
const original = mountHash[mount] || mount;
mount = original;

({ mount } = await plugins.hooks.fire('filter:router.add', { mount }));
if (mount === null) { // do not mount at all
Expand All @@ -152,12 +153,12 @@ async function addCoreRoutes(app, router, middleware) {
if (mount !== original) {
// Set up redirect for fallback handling (some js/tpls may still refer to the traditional mount point)
winston.info(`[router] /${original} prefix re-mounted to /${mount}. Requests to /${original}/* will now redirect to /${mount}`);
router.use(new RegExp(`/(api/)?${mountHash[original] || original}`), (req, res) => {
router.use(new RegExp(`/(api/)?${original}`), (req, res) => {
controllerHelpers.redirect(res, `${nconf.get('relative_path')}/${mount}${req.path}`);
});
}

_mounts[original](router, mount, middleware, controllers);
_mounts[method](router, mount, middleware, controllers);
}));

const relativePath = nconf.get('relative_path');
Expand Down

0 comments on commit bc68e99

Please sign in to comment.