backend-app-api: remove startHttpServer

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-01-10 12:19:06 +01:00
parent bd20e8b925
commit bff790af9c
4 changed files with 19 additions and 82 deletions
-16
View File
@@ -222,22 +222,6 @@ export type ServiceOrExtensionPoint<T = unknown> =
| ExtensionPoint<T>
| ServiceRef<T>;
// @public
export function startHttpServer(
listener: RequestListener,
options: StartHttpServerOptions,
): Promise<void>;
// @public
export interface StartHttpServerOptions {
// (undocumented)
config: ConfigService;
// (undocumented)
lifecycle: RootLifecycleService;
// (undocumented)
logger: RootLoggerService;
}
// @public (undocumented)
export const tokenManagerFactory: (
options?: undefined,
@@ -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,
@@ -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();
}
@@ -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;
},