|
|
|
@ -10,13 +10,21 @@ export const rrouters = < |
|
|
|
|
>( |
|
|
|
|
app: A, |
|
|
|
|
union: Readonly<M> | R, |
|
|
|
|
{ key, route = '/' }: { key?: string; route?: string } = {}, |
|
|
|
|
{ |
|
|
|
|
assign = (router) => [router], |
|
|
|
|
key, |
|
|
|
|
route = '/', |
|
|
|
|
}: { |
|
|
|
|
assign?: (router: R) => R[]; |
|
|
|
|
key?: keyof M; |
|
|
|
|
route?: string; |
|
|
|
|
} = {}, |
|
|
|
|
) => { |
|
|
|
|
if ('route' in union) { |
|
|
|
|
stdout(`Setting up route ${route}`); |
|
|
|
|
app.use(route, union as R); |
|
|
|
|
app.use(route, ...assign(union as R)); |
|
|
|
|
} else if (key) { |
|
|
|
|
rrouters(app, union[key], { route: path.posix.join(route, key) }); |
|
|
|
|
rrouters(app, union[key], { route: path.posix.join(route, String(key)) }); |
|
|
|
|
} else { |
|
|
|
|
Object.entries(union).forEach(([extend, subunion]) => { |
|
|
|
|
rrouters(app, subunion, { route: path.posix.join(route, extend) }); |
|
|
|
|