fix(core): update

This commit is contained in:
Philipp Kunz 2019-09-01 16:54:36 +02:00
parent 9c1504ef02
commit ef61ea9ad7

View File

@ -10,6 +10,7 @@ import { UniverseConnection } from './smartuniverse.classes.universeconnection';
export interface ISmartUniverseConstructorOptions { export interface ISmartUniverseConstructorOptions {
messageExpiryInMilliseconds: number; messageExpiryInMilliseconds: number;
externalServer?: plugins.smartexpress.Server;
} }
/** /**
@ -68,14 +69,18 @@ export class Universe {
*/ */
public async start(portArg: number) { public async start(portArg: number) {
// lets create the base smartexpress server // lets create the base smartexpress server
this.smartexpressServer = new plugins.smartexpress.Server({ if (!this.options.externalServer) {
cors: true, this.smartexpressServer = new plugins.smartexpress.Server({
defaultAnswer: async () => { cors: true,
return `smartuniverse server ${this.getUniverseVersion()}`; defaultAnswer: async () => {
}, return `smartuniverse server ${this.getUniverseVersion()}`;
forceSsl: false, },
port: portArg forceSsl: false,
}); port: portArg
});
} else {
this.smartexpressServer = this.options.externalServer;
}
// add websocket upgrade // add websocket upgrade
this.smartsocket = new plugins.smartsocket.Smartsocket({}); this.smartsocket = new plugins.smartsocket.Smartsocket({});
@ -148,7 +153,9 @@ export class Universe {
// add smartsocket to the running smartexpress app // add smartsocket to the running smartexpress app
this.smartsocket.setExternalServer('smartexpress', this.smartexpressServer as any); this.smartsocket.setExternalServer('smartexpress', this.smartexpressServer as any);
// start everything // start everything
await this.smartexpressServer.start(); if (!this.options.externalServer) {
await this.smartexpressServer.start();
}
await this.smartsocket.start(); await this.smartsocket.start();
plugins.smartlog.defaultLogger.log('success', 'started universe'); plugins.smartlog.defaultLogger.log('success', 'started universe');
} }
@ -158,6 +165,8 @@ export class Universe {
*/ */
public async stopServer() { public async stopServer() {
await this.smartsocket.stop(); await this.smartsocket.stop();
await this.smartexpressServer.stop(); if (!this.options.externalServer) {
await this.smartexpressServer.stop();
}
} }
} }