Merge branch 'main' into versions/6.0.0

# Conflicts:
#	src/init/ServerInitializer.ts
#	src/server/BaseHttpServerFactory.ts
#	src/server/HttpServerFactory.ts
#	src/server/WebSocketServerFactory.ts
#	test/unit/server/BaseHttpServerFactory.test.ts
This commit is contained in:
Joachim Van Herwegen
2023-02-01 10:13:04 +01:00
30 changed files with 972 additions and 653 deletions

View File

@@ -14,22 +14,32 @@ export class ServerInitializer extends Initializer implements Finalizable {
protected readonly logger = getLoggerFor(this);
private readonly serverFactory: HttpServerFactory;
private readonly port: number;
private readonly port?: number;
private readonly socketPath?: string;
private server?: Server;
public constructor(serverFactory: HttpServerFactory, port: number) {
public constructor(serverFactory: HttpServerFactory, port?: number, socketPath?: string) {
super();
this.serverFactory = serverFactory;
this.port = port;
this.socketPath = socketPath;
if (!port && !socketPath) {
throw new Error('Either Port or Socket arguments must be set');
}
}
public async handle(): Promise<void> {
this.server = await this.serverFactory.createServer();
const url = new URL(`http${isHttpsServer(this.server) ? 's' : ''}://localhost:${this.port}/`).href;
this.logger.info(`Listening to server at ${url}`);
this.server.listen(this.port);
if (this.socketPath) {
this.logger.info(`Listening to server at ${this.server.address()}`);
this.server.listen(this.socketPath);
} else {
const url = new URL(`http${isHttpsServer(this.server) ? 's' : ''}://localhost:${this.port}/`).href;
this.logger.info(`Listening to server at ${url}`);
this.server.listen(this.port);
}
}
public async finalize(): Promise<void> {