fix(striker-ui-api): allow customize handlers per route batch in register routers function

main
Tsu-ba-me 2 years ago
parent 73fa311272
commit c40b7ff7d4
  1. 14
      striker-ui-api/src/lib/rrouters.ts

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

Loading…
Cancel
Save