Allow to prefix forest routes in express

What is the feature?

We are using express and forest-express-sequelize and we scope all our forest routes in a /admin path. Doing so makes the smart actions not work.

There are hacky ways of fixing it (see below) but it would be much cleaner to be able to set this as a config parameter of the init function (or somewhere else)

What problem does this solve for you?

With version 7, we faced an issue with smart actions not working anymore and you recommended to us, in a conference call, to add this hacky middleware to fix the issue:

(req, _res, next) => {
  req.originalUrl = req.originalUrl.replace('/admin', '');
  return next();
},

Migrating to the version 8 made this issue re-appear as you are not using originalUrl anymore so we updated the middleware to:

(req, _res, next) => {
  req.baseUrl = req.baseUrl.replace('/admin', '');
  return next();
},

Who else would be using this feature?

Anybody using express that wants to scope the forest routes in a specific subpath.

Hello @Vincent_Francois ,

Your request has been added to our product board :slight_smile:

1 Like