@@ -4,21 +4,18 @@ import {RoutesTypes, RouteTypes} from '../utils/interfacesandenums';
4
4
import { logError , yellow , logWarn } from '../utils/log' ;
5
5
6
6
export const addOptionalRoutes = async ( routeList = [ ] as string [ ] ) : Promise < HandledRoute [ ] > => {
7
- const routesToGenerate = await routeList . reduce (
8
- async ( result : Promise < HandledRoute [ ] > , cur : string ) => {
9
- const x = await result ;
10
- if ( scullyConfig . routes [ cur ] ) {
11
- const r = await routePluginHandler ( cur ) ;
12
- x . push ( ...r ) ;
13
- } else if ( cur . includes ( '/:' ) ) {
14
- logWarn ( `No configuration for route "${ yellow ( cur ) } " found. Skipping` ) ;
15
- } else {
16
- x . push ( { route : cur , type : RouteTypes . default } ) ;
17
- }
18
- return x ;
19
- } ,
20
- Promise . resolve ( [ ] as HandledRoute [ ] )
21
- ) ;
7
+ const routesToGenerate = await routeList . reduce ( async ( result : Promise < HandledRoute [ ] > , cur : string ) => {
8
+ const x = await result ;
9
+ if ( scullyConfig . routes [ cur ] ) {
10
+ const r = await routePluginHandler ( cur ) ;
11
+ x . push ( ...r ) ;
12
+ } else if ( cur . includes ( '/:' ) ) {
13
+ logWarn ( `No configuration for route "${ yellow ( cur ) } " found. Skipping` ) ;
14
+ } else {
15
+ x . push ( { route : cur , type : RouteTypes . default } ) ;
16
+ }
17
+ return x ;
18
+ } , Promise . resolve ( [ ] as HandledRoute [ ] ) ) ;
22
19
23
20
return routesToGenerate ;
24
21
} ;
@@ -44,7 +41,19 @@ async function routePluginHandler(route: string): Promise<HandledRoute[]> {
44
41
return [ { route, type : RouteTypes . default } ] ;
45
42
}
46
43
if ( plugins . router [ conf . type ] ) {
47
- return ( plugins . router [ conf . type ] ( route , conf ) as unknown ) as HandledRoute [ ] ;
44
+ const generatedRoutes = ( await ( plugins . router [ conf . type ] ( route , conf ) as unknown ) ) as HandledRoute [ ] ;
45
+ generatedRoutes . forEach ( handledRoute => {
46
+ if ( ! handledRoute . route . startsWith ( '/' ) ) {
47
+ logWarn (
48
+ `The plugin '${
49
+ conf . type
50
+ } ' needs to return handledRoutes with a route that starts with '/'. The route ${ JSON . stringify (
51
+ handledRoute
52
+ ) } is invalid.`
53
+ ) ;
54
+ }
55
+ } ) ;
56
+ return generatedRoutes ;
48
57
}
49
58
return [ { route, type : RouteTypes . default } ] ;
50
59
}
0 commit comments