Express 5.0.0 contained a number of breaking changes, including the removal of support for RegExp in strings.
Documentation provides guidance to replace RegExps that were used to construct the route patterns, but I cannot find any documentation on type guarding route parameters like you were able to in Express 4.
Example:
Express 4
I have middleware that sets an ‘application context’ for all requests. It does so if the route follows the pattern /applicationID
, where application ID is a UUID.
const applicationContext = Router({ mergeParams: true });
applicationContext.use('/:applicationID([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})',
function (req, res, next) {
return requireRouteParamsMiddleware([ 'applicationID' ])(req, res, (err) => {
if (err) {
return next(err);
}
return setApplicationContext(req, res, next);
});
});
Question: How would I be able to achieve the same in Express 5, type guarding the applicationID
route parameter to only match upon matching the UUID RegExp pattern?
Thanks for your help in advance!
I tried substituting the string with a new RegExp(...)
but quickly realised that (to my knowledge) there was no way to retain the route parameter name in doing so.