From bff790af9c4a8c0f96bd3ecd3150062c7e66e3d8 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Tue, 10 Jan 2023 12:19:06 +0100 Subject: [PATCH] backend-app-api: remove startHttpServer Signed-off-by: Patrik Oldsberg --- packages/backend-app-api/api-report.md | 16 ----- packages/backend-app-api/src/http/index.ts | 2 - .../src/http/startHttpServer.ts | 62 ------------------- .../rootHttpRouter/rootHttpRouterFactory.ts | 21 ++++++- 4 files changed, 19 insertions(+), 82 deletions(-) delete mode 100644 packages/backend-app-api/src/http/startHttpServer.ts diff --git a/packages/backend-app-api/api-report.md b/packages/backend-app-api/api-report.md index 18c2c52370..cc84309a2f 100644 --- a/packages/backend-app-api/api-report.md +++ b/packages/backend-app-api/api-report.md @@ -222,22 +222,6 @@ export type ServiceOrExtensionPoint = | ExtensionPoint | ServiceRef; -// @public -export function startHttpServer( - listener: RequestListener, - options: StartHttpServerOptions, -): Promise; - -// @public -export interface StartHttpServerOptions { - // (undocumented) - config: ConfigService; - // (undocumented) - lifecycle: RootLifecycleService; - // (undocumented) - logger: RootLoggerService; -} - // @public (undocumented) export const tokenManagerFactory: ( options?: undefined, diff --git a/packages/backend-app-api/src/http/index.ts b/packages/backend-app-api/src/http/index.ts index 5bd54ec4a5..4a9ec14cf8 100644 --- a/packages/backend-app-api/src/http/index.ts +++ b/packages/backend-app-api/src/http/index.ts @@ -23,8 +23,6 @@ export type { } from './MiddlewareFactory'; export { readCorsOptions } from './readCorsOptions'; export { readHelmetOptions } from './readHelmetOptions'; -export { startHttpServer } from './startHttpServer'; -export type { StartHttpServerOptions } from './startHttpServer'; export type { ExtendedHttpServer, HttpServerCertificateOptions, diff --git a/packages/backend-app-api/src/http/startHttpServer.ts b/packages/backend-app-api/src/http/startHttpServer.ts deleted file mode 100644 index 64d0be3f1e..0000000000 --- a/packages/backend-app-api/src/http/startHttpServer.ts +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2023 The Backstage Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { - ConfigService, - RootLifecycleService, - RootLoggerService, -} from '@backstage/backend-plugin-api'; -import { RequestListener } from 'http'; -import { readHttpServerOptions } from './config'; -import { createHttpServer } from './createHttpServer'; - -/** - * Options for {@link startHttpServer}. - * - * @public - */ -export interface StartHttpServerOptions { - config: ConfigService; - logger: RootLoggerService; - lifecycle: RootLifecycleService; -} - -/** - * Starts up an HTTP server, as well as registers a shutdown handler that stops the server. - * - * @public - */ -export async function startHttpServer( - listener: RequestListener, - options: StartHttpServerOptions, -) { - const { config, logger, lifecycle } = options; - - const server = await createHttpServer( - listener, - readHttpServerOptions(config.getOptionalConfig('backend')), - { logger }, - ); - - lifecycle.addShutdownHook({ - async fn() { - await server.stop(); - }, - labels: { type: 'httpServer' }, - }); - - await server.start(); -} diff --git a/packages/backend-app-api/src/services/implementations/rootHttpRouter/rootHttpRouterFactory.ts b/packages/backend-app-api/src/services/implementations/rootHttpRouter/rootHttpRouterFactory.ts index 284b019a2e..4b021b977c 100644 --- a/packages/backend-app-api/src/services/implementations/rootHttpRouter/rootHttpRouterFactory.ts +++ b/packages/backend-app-api/src/services/implementations/rootHttpRouter/rootHttpRouterFactory.ts @@ -22,7 +22,11 @@ import { LoggerService, } from '@backstage/backend-plugin-api'; import express, { RequestHandler, Express } from 'express'; -import { MiddlewareFactory, startHttpServer } from '../../../http'; +import { + createHttpServer, + MiddlewareFactory, + readHttpServerOptions, +} from '../../../http'; import { RestrictedIndexedRouter } from './RestrictedIndexedRouter'; /** @@ -93,7 +97,20 @@ export const rootHttpRouterFactory = createServiceFactory({ lifecycle, }); - await startHttpServer(app, { config, logger, lifecycle }); + const server = await createHttpServer( + app, + readHttpServerOptions(config.getOptionalConfig('backend')), + { logger }, + ); + + lifecycle.addShutdownHook({ + async fn() { + await server.stop(); + }, + labels: { service: 'rootHttpRouter' }, + }); + + await server.start(); return router; },