diff --git a/scully/routerPlugins/addOptionalRoutesPlugin.ts b/scully/routerPlugins/addOptionalRoutesPlugin.ts index ebcaaf2b8..cc64e4bfd 100644 --- a/scully/routerPlugins/addOptionalRoutesPlugin.ts +++ b/scully/routerPlugins/addOptionalRoutesPlugin.ts @@ -4,21 +4,18 @@ import {RoutesTypes, RouteTypes} from '../utils/interfacesandenums'; import {logError, yellow, logWarn} from '../utils/log'; export const addOptionalRoutes = async (routeList = [] as string[]): Promise => { - const routesToGenerate = await routeList.reduce( - async (result: Promise, cur: string) => { - const x = await result; - if (scullyConfig.routes[cur]) { - const r = await routePluginHandler(cur); - x.push(...r); - } else if (cur.includes('/:')) { - logWarn(`No configuration for route "${yellow(cur)}" found. Skipping`); - } else { - x.push({route: cur, type: RouteTypes.default}); - } - return x; - }, - Promise.resolve([] as HandledRoute[]) - ); + const routesToGenerate = await routeList.reduce(async (result: Promise, cur: string) => { + const x = await result; + if (scullyConfig.routes[cur]) { + const r = await routePluginHandler(cur); + x.push(...r); + } else if (cur.includes('/:')) { + logWarn(`No configuration for route "${yellow(cur)}" found. Skipping`); + } else { + x.push({route: cur, type: RouteTypes.default}); + } + return x; + }, Promise.resolve([] as HandledRoute[])); return routesToGenerate; }; @@ -44,7 +41,19 @@ async function routePluginHandler(route: string): Promise { return [{route, type: RouteTypes.default}]; } if (plugins.router[conf.type]) { - return (plugins.router[conf.type](route, conf) as unknown) as HandledRoute[]; + const generatedRoutes = (await (plugins.router[conf.type](route, conf) as unknown)) as HandledRoute[]; + generatedRoutes.forEach(handledRoute => { + if (!handledRoute.route.startsWith('/')) { + logWarn( + `The plugin '${ + conf.type + }' needs to return handledRoutes with a route that starts with '/'. The route ${JSON.stringify( + handledRoute + )} is invalid.` + ); + } + }); + return generatedRoutes; } return [{route, type: RouteTypes.default}]; }