chore: added in the router things:

Co-authored-by: Johan Haals <johan.haals@gmail.com>
Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
blam
2022-07-06 16:41:49 +02:00
committed by Patrik Oldsberg
parent 5da7205bad
commit f6404275c7
3 changed files with 29 additions and 5 deletions
@@ -30,18 +30,18 @@ export const httpRouterFactory = createServiceFactory({
},
factory: async ({ configFactory }) => {
const rootRouter = Router();
const service = createServiceBuilder(module)
.loadConfig(await configFactory('root'))
.addRouter('', rootRouter);
await service.start();
return async (pluginId?: string) => {
if (!pluginId) {
return rootRouter;
}
const path = pluginId ? `/api/${pluginId}` : '';
return {
use(handler: Handler) {
rootRouter.use(`/api/${pluginId}`, handler);
rootRouter.use(path, handler);
},
};
};
@@ -79,6 +79,6 @@ export function createServiceFactory<
Api,
Impl extends Api,
Deps extends { [name in string]: unknown },
>(factory: ServiceFactory<Api, Impl, Deps>): ServiceFactory<Api, Impl, Deps> {
>(factory: ServiceFactory<Api, Impl, Deps>): ServiceFactory<Api, Api, {}> {
return factory;
}
+24
View File
@@ -39,6 +39,30 @@ import {
// },
// });
// export const appPlugin = createBackendPlugin({
// id: 'app',
// register(env) {
// env.registerInit({
// deps: {
// httpRouter: httpRouterServiceRef,
// database: databaseServiceRef,
// logger: loggerServiceRef,
// config: configServiceRef,
// },
// async init({ httpRouter, config, logger, database }) {
// console.log('App plugin init');
// const appBackendRoute = await createAppBackendRouter({
// appPackageName: 'example-app',
// config,
// logger: loggerToWinstonLogger(logger),
// database,
// });
// },
// });
// },
// });
const backend = createBackend({
apis: [],
});