From 3eb235ea9b643f7b09482614f648562a2da043e3 Mon Sep 17 00:00:00 2001 From: jjak0b Date: Wed, 24 Mar 2021 01:09:45 +0100 Subject: [PATCH] feat(service): Now express app can be mounted even if sw is already active --- src/service.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/service.js b/src/service.js index 4fe791c..c8c0c81 100644 --- a/src/service.js +++ b/src/service.js @@ -24,6 +24,17 @@ class Server { this.serverApp = express(); this.port = 80; this.registerService(); + + this.promiseMount + .then( (app) => { + if(!this.mountUrl) { + this.mountUrl = new Url( self.registration.scope ); + } + let mountPath = this.mountUrl.pathname; + this.serverApp.all( "*", mountExpressAt( mountPath ) ); + this.serverApp.use( this.mountUrl.pathname, app ) + debug("Mounted app @", this.mountUrl.toString() ); + }) } registerService() { @@ -46,14 +57,7 @@ class Server { this.mountUrl = new Url( self.registration.scope ); let mountPath = this.mountUrl.pathname; - this.serverApp.all( "*", mountExpressAt( mountPath ) ); debug('installed at mount: \"%s\"', mountPath, self.registration ); - - this.promiseMount - .then( (app) => { - this.serverApp.use( this.mountUrl.pathname, app ) - debug("Mounted app @", this.mountUrl.toString() ); - }) } onActivate(event) {