refactor: Add ExpressHttpServerFactory.

This commit is contained in:
Ruben Verborgh
2020-11-20 14:49:28 +01:00
committed by Joachim Van Herwegen
parent 4ef4d44a3a
commit e39e7963eb
8 changed files with 31 additions and 22 deletions

View File

@@ -4,8 +4,9 @@ import type { Express } from 'express';
import express from 'express';
import { getLoggerFor } from '../logging/LogUtil';
import type { HttpHandler } from './HttpHandler';
import type { HttpServerFactory } from './HttpServerFactory';
export class ExpressHttpServer {
export class ExpressHttpServerFactory implements HttpServerFactory {
protected readonly logger = getLoggerFor(this);
private readonly handler: HttpHandler;
@@ -14,7 +15,7 @@ export class ExpressHttpServer {
this.handler = handler;
}
public listen(port?: number): Server {
public startServer(port: number): Server {
const app = express();
this.setup(app);
return app.listen(port);

View File

@@ -0,0 +1,8 @@
import type { Server } from 'http';
/**
* A factory for HTTP servers
*/
export interface HttpServerFactory {
startServer: (port: number) => Server;
}