cherry-pick features/react-routes

This commit is contained in:
Iuri Matias 2018-07-13 10:50:57 +03:00
parent e7066cd1f3
commit 68805d4e08
3 changed files with 18 additions and 13 deletions

View File

@ -311,9 +311,7 @@ Config.prototype.loadCommunicationConfigFile = function() {
Config.prototype.loadWebServerConfigFile = function() {
var configObject = {
"enabled": true,
"host": defaultHost,
"port": 8000
"enabled": true, "host": defaultHost, "port": 8000, "enableCatchAll": true
};
let configFilePath = this._getFileOrOject(this.configDir, 'webserver', 'webserver');

View File

@ -16,6 +16,7 @@ class WebServer {
this.host = options.host || this.webServerConfig.host;
this.port = options.port || this.webServerConfig.port;
this.enableCatchAll = this.webServerConfig.enableCatchAll === true;
this.events.emit("status", __("Starting Server"));
this.server = new Server({host: this.host, port: this.port});

View File

@ -29,23 +29,29 @@ class Server {
var app = express();
app.use(serve);
app.use('/embark', serveStatic(path.join(__dirname, 'backend'), {'backend': ['index.html', 'index.htm']}));
app.use(express.static(path.join(fs.dappPath(this.dist)), {'index': ['index.html', 'index.htm']}));
app.use(['/embark', '/backend', '/admin'], express.static(path.join(__dirname, 'backend'), {'index': ['index.html', 'index.htm']})); // mount the sub app
app.use(bodyParser.json()); // support json encoded bodies
app.use(bodyParser.urlencoded({ extended: true })); // support encoded bodies
expressWebSocket(app);
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]);
}
}
app.get('/embark', function (req, res) {
res.send('Welcome to Embark')
});
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')));
}
}
app.listen(this.port);