mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Split up server creation and request handling
This allows us to decouple the WebSocket listening from the HTTP configs, making these features completely orthogonal.
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import type { Server } from 'http';
|
||||
import { URL } from 'url';
|
||||
import { promisify } from 'util';
|
||||
import { getLoggerFor } from '../logging/LogUtil';
|
||||
import { isHttpsServer } from '../server/HttpServerFactory';
|
||||
import type { HttpServerFactory } from '../server/HttpServerFactory';
|
||||
import type { Finalizable } from './final/Finalizable';
|
||||
import { Initializer } from './Initializer';
|
||||
@@ -8,6 +11,8 @@ import { Initializer } from './Initializer';
|
||||
* Creates and starts an HTTP server.
|
||||
*/
|
||||
export class ServerInitializer extends Initializer implements Finalizable {
|
||||
protected readonly logger = getLoggerFor(this);
|
||||
|
||||
private readonly serverFactory: HttpServerFactory;
|
||||
private readonly port: number;
|
||||
|
||||
@@ -20,7 +25,11 @@ export class ServerInitializer extends Initializer implements Finalizable {
|
||||
}
|
||||
|
||||
public async handle(): Promise<void> {
|
||||
this.server = this.serverFactory.startServer(this.port);
|
||||
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);
|
||||
}
|
||||
|
||||
public async finalize(): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user