root htt router too

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2023-02-07 11:15:21 +01:00
parent b729f9f31f
commit 5f98a682bb
3 changed files with 37 additions and 38 deletions
+1 -1
View File
@@ -2,4 +2,4 @@
'@backstage/backend-app-api': patch
---
Moved the options of the config service out to the factory itself, where it belongs
Moved the options of the `config` and `rootHttpRouter` services out to the factories themselves, where they belong
+3 -1
View File
@@ -232,7 +232,9 @@ export interface RootHttpRouterConfigureOptions {
}
// @public (undocumented)
export const rootHttpRouterFactory: () => ServiceFactory<RootHttpRouterService>;
export const rootHttpRouterFactory: (
options?: RootHttpRouterFactoryOptions | undefined,
) => ServiceFactory<RootHttpRouterService>;
// @public (undocumented)
export type RootHttpRouterFactoryOptions = {
@@ -69,45 +69,42 @@ function defaultConfigure({
}
/** @public */
export const rootHttpRouterFactory = createServiceFactory({
service: coreServices.rootHttpRouter,
deps: {
config: coreServices.config,
rootLogger: coreServices.rootLogger,
lifecycle: coreServices.rootLifecycle,
},
async factory(
{ config, rootLogger, lifecycle },
{
indexPath,
configure = defaultConfigure,
}: RootHttpRouterFactoryOptions = {},
) {
const logger = rootLogger.child({ service: 'rootHttpRouter' });
const app = express();
export const rootHttpRouterFactory = createServiceFactory(
(options?: RootHttpRouterFactoryOptions) => ({
service: coreServices.rootHttpRouter,
deps: {
config: coreServices.config,
rootLogger: coreServices.rootLogger,
lifecycle: coreServices.rootLifecycle,
},
async factory({ config, rootLogger, lifecycle }) {
const { indexPath, configure = defaultConfigure } = options ?? {};
const logger = rootLogger.child({ service: 'rootHttpRouter' });
const app = express();
const router = DefaultRootHttpRouter.create({ indexPath });
const middleware = MiddlewareFactory.create({ config, logger });
const router = DefaultRootHttpRouter.create({ indexPath });
const middleware = MiddlewareFactory.create({ config, logger });
configure({
app,
routes: router.handler(),
middleware,
config,
logger,
lifecycle,
});
configure({
app,
routes: router.handler(),
middleware,
config,
logger,
lifecycle,
});
const server = await createHttpServer(
app,
readHttpServerOptions(config.getOptionalConfig('backend')),
{ logger },
);
const server = await createHttpServer(
app,
readHttpServerOptions(config.getOptionalConfig('backend')),
{ logger },
);
lifecycle.addShutdownHook(() => server.stop());
lifecycle.addShutdownHook(() => server.stop());
await server.start();
await server.start();
return router;
},
});
return router;
},
}),
);