From 17233abfcbc37915b0d9158c3284811ef49c243a Mon Sep 17 00:00:00 2001 From: Tobias Andersen Date: Thu, 20 Aug 2020 14:55:42 +0200 Subject: [PATCH] =Partial commit, have to go home --- .../src/service/lib/ServiceBuilderImpl.ts | 6 ++- .../src/service/lib/hostFactory.ts | 41 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 packages/backend-common/src/service/lib/hostFactory.ts diff --git a/packages/backend-common/src/service/lib/ServiceBuilderImpl.ts b/packages/backend-common/src/service/lib/ServiceBuilderImpl.ts index 0e0feb6a37..e75ae8069f 100644 --- a/packages/backend-common/src/service/lib/ServiceBuilderImpl.ts +++ b/packages/backend-common/src/service/lib/ServiceBuilderImpl.ts @@ -38,6 +38,10 @@ import { readHttpsSettings, HttpsSettings, } from './config'; +import { + createHttpServer, + createHttpsServer, +} from './hostFactory'; const DEFAULT_PORT = 7000; // '' is express default, which listens to all interfaces @@ -215,7 +219,7 @@ export class ServiceBuilderImpl implements ServiceBuilder { } else { logger.info('Initializing http server'); - server = http.createServer(app); + server = createHttpServer(app); } const stoppableServer = stoppable( diff --git a/packages/backend-common/src/service/lib/hostFactory.ts b/packages/backend-common/src/service/lib/hostFactory.ts new file mode 100644 index 0000000000..9b850431fb --- /dev/null +++ b/packages/backend-common/src/service/lib/hostFactory.ts @@ -0,0 +1,41 @@ +/* + * Copyright 2020 Spotify AB + * + * 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 express from 'express'; +import * as http from 'http'; +import * as https from 'https'; + +/** + * Reads some base options out of a config object. + * + * @param config The root of a backend config object + * @returns A base options object + * + * @example + * ```json + * { + * baseUrl: "http://localhost:7000", + * listen: "0.0.0.0:7000" + * } + * ``` + */ +export function createHttpServer(app: express.Express): http.Server { + return http.createServer(app); +} + + +export function createHttpsServer(app: express.Express): http.Server { + return https.createServer(app); +} \ No newline at end of file