From 50740211da21740d1dd62a91d31f8b8b6a807d32 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Fri, 13 Jul 2018 10:50:57 +0300 Subject: [PATCH] cherry-pick features/react-routes --- lib/core/config.js | 3 ++- lib/modules/webserver/index.js | 1 + lib/modules/webserver/server.js | 20 ++++++++++++++------ 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/core/config.js b/lib/core/config.js index 1f5759cb..299c9447 100644 --- a/lib/core/config.js +++ b/lib/core/config.js @@ -387,7 +387,8 @@ Config.prototype.loadWebServerConfigFile = function() { "enabled": true, "host": defaultHost, "openBrowser": true, - "port": 8000 + "port": 8000, + "enableCatchAll": true }; let configFilePath = this._getFileOrOject(this.configDir, 'webserver', 'webserver'); diff --git a/lib/modules/webserver/index.js b/lib/modules/webserver/index.js index 7a226aba..346625b7 100644 --- a/lib/modules/webserver/index.js +++ b/lib/modules/webserver/index.js @@ -23,6 +23,7 @@ class WebServer { this.host = this.webServerConfig.host; this.port = parseInt(this.webServerConfig.port, 10); + this.enableCatchAll = this.webServerConfig.enableCatchAll === true; this.events.emit("status", __("Starting Server")); diff --git a/lib/modules/webserver/server.js b/lib/modules/webserver/server.js index 9816084c..21ddeb65 100644 --- a/lib/modules/webserver/server.js +++ b/lib/modules/webserver/server.js @@ -77,12 +77,13 @@ class Server { }); }); - let apiCalls = self.plugins.getPluginsProperty("apiCalls", "apiCalls"); - console.dir(apiCalls); - for (let apiCall of apiCalls) { - console.dir("adding " + apiCall.method + " " + apiCall.endpoint); - app[apiCall.method].apply(app, [apiCall.endpoint, apiCall.cb]); - } + if (self.plugins) { + let apiCalls = self.plugins.getPluginsProperty("apiCalls", "apiCalls"); + for (let apiCall of apiCalls) { + console.dir("adding " + apiCall.method + " " + apiCall.endpoint); + app[apiCall.method].apply(app, [apiCall.endpoint, apiCall.cb]); + } + } this.app.ws('/', function(ws, _req) { self.events.on('outputDone', () => { @@ -97,6 +98,13 @@ class Server { }); }); + if (this.enableCatchAll === true) { + app.get('/*', function (req, res) { + self.logger.trace('webserver> GET ' + req.path); + res.sendFile(path.join(fs.dappPath(self.dist, 'index.html'))); + } + } + async.waterfall([ function createPlaceholderPage(next) { if (!self.isFirstStart) {