Разделите ваши функции обработчика, чтобы изолировать функции.
app.get('/ts/:space/:mode/:param1/:param2/:fromdate/:todate', handler1)
app.get('/ts/:space/:mode/:param1/:param2/:param3/:fromdate/:todate', handler2)
и трюк для handler1
особый случай:
const handler1 = (req,res,next) => {
if (req.params.space === "blah") {
// use hanler for `/ts/:space/:mode/:param1/:param2/:param3/:fromdate/:todate` route
// force set param3 value,
req.params['param3'] = "maybe_a_default_value";
return handler2(req,res,next);
}
// handler for `/ts/:space/:mode/:param1/:param2/:fromdate/:todate` route
}
const handler2 = (req,res,next) => {
// handler for `/ts/:space/:mode/:param1/:param2/:param3/:fromdate/:todate`
// now, req.params.space === "blah" and req.params.param3 === "maybe_a_default_value"
}