diff --git a/project/src/servers/HttpServer.ts b/project/src/servers/HttpServer.ts index 952ed451..b1c6928d 100644 --- a/project/src/servers/HttpServer.ts +++ b/project/src/servers/HttpServer.ts @@ -17,6 +17,7 @@ import { LocalisationService } from "@spt-aki/services/LocalisationService"; export class HttpServer { protected httpConfig: IHttpConfig; + protected started: boolean; constructor( @inject("WinstonLogger") protected logger: ILogger, @@ -37,6 +38,8 @@ export class HttpServer */ public load(): void { + this.started = false; + /* create server */ const httpServer: Server = http.createServer(); @@ -48,6 +51,7 @@ export class HttpServer /* Config server to listen on a port */ httpServer.listen(this.httpConfig.port, this.httpConfig.ip, () => { + this.started = true; this.logger.success( this.localisationService.getText("started_webserver_success", this.httpServerHelper.getBackendUrl()), ); @@ -123,4 +127,9 @@ export class HttpServer return found; } + + public isStarted(): boolean + { + return this.started; + } } diff --git a/project/src/utils/App.ts b/project/src/utils/App.ts index 9b51b1aa..235926b4 100644 --- a/project/src/utils/App.ts +++ b/project/src/utils/App.ts @@ -7,6 +7,7 @@ import { ConfigTypes } from "@spt-aki/models/enums/ConfigTypes"; import { ICoreConfig } from "@spt-aki/models/spt/config/ICoreConfig"; import { ILogger } from "@spt-aki/models/spt/utils/ILogger"; import { ConfigServer } from "@spt-aki/servers/ConfigServer"; +import { HttpServer } from "@spt-aki/servers/HttpServer"; import { LocalisationService } from "@spt-aki/services/LocalisationService"; import { EncodingUtil } from "@spt-aki/utils/EncodingUtil"; import { TimeUtil } from "@spt-aki/utils/TimeUtil"; @@ -23,6 +24,7 @@ export class App @inject("LocalisationService") protected localisationService: LocalisationService, @inject("ConfigServer") protected configServer: ConfigServer, @inject("EncodingUtil") protected encodingUtil: EncodingUtil, + @inject("HttpServer") protected httpServer: HttpServer, @injectAll("OnLoad") protected onLoadComponents: OnLoad[], @injectAll("OnUpdate") protected onUpdateComponents: OnUpdate[], ) @@ -64,6 +66,12 @@ export class App protected async update(onUpdateComponents: OnUpdate[]): Promise { + // If the server has failed to start, skip any update calls + if (!this.httpServer.isStarted()) + { + return; + } + for (const updateable of onUpdateComponents) { let success = false;