From ef61ea9ad792ed84f03f15f86a318ca18cb47c90 Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Sun, 1 Sep 2019 16:54:36 +0200 Subject: [PATCH] fix(core): update --- ts/smartuniverse.classes.universe.ts | 29 ++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/ts/smartuniverse.classes.universe.ts b/ts/smartuniverse.classes.universe.ts index e75d9c5..79f9842 100644 --- a/ts/smartuniverse.classes.universe.ts +++ b/ts/smartuniverse.classes.universe.ts @@ -10,6 +10,7 @@ import { UniverseConnection } from './smartuniverse.classes.universeconnection'; export interface ISmartUniverseConstructorOptions { messageExpiryInMilliseconds: number; + externalServer?: plugins.smartexpress.Server; } /** @@ -68,14 +69,18 @@ export class Universe { */ public async start(portArg: number) { // lets create the base smartexpress server - this.smartexpressServer = new plugins.smartexpress.Server({ - cors: true, - defaultAnswer: async () => { - return `smartuniverse server ${this.getUniverseVersion()}`; - }, - forceSsl: false, - port: portArg - }); + if (!this.options.externalServer) { + this.smartexpressServer = new plugins.smartexpress.Server({ + cors: true, + defaultAnswer: async () => { + return `smartuniverse server ${this.getUniverseVersion()}`; + }, + forceSsl: false, + port: portArg + }); + } else { + this.smartexpressServer = this.options.externalServer; + } // add websocket upgrade this.smartsocket = new plugins.smartsocket.Smartsocket({}); @@ -148,7 +153,9 @@ export class Universe { // add smartsocket to the running smartexpress app this.smartsocket.setExternalServer('smartexpress', this.smartexpressServer as any); // start everything - await this.smartexpressServer.start(); + if (!this.options.externalServer) { + await this.smartexpressServer.start(); + } await this.smartsocket.start(); plugins.smartlog.defaultLogger.log('success', 'started universe'); } @@ -158,6 +165,8 @@ export class Universe { */ public async stopServer() { await this.smartsocket.stop(); - await this.smartexpressServer.stop(); + if (!this.options.externalServer) { + await this.smartexpressServer.stop(); + } } }