cherry-pick features/react-routes
This commit is contained in:
parent
300d2532aa
commit
4d067b82f4
|
@ -309,7 +309,7 @@ Config.prototype.loadCommunicationConfigFile = function() {
|
|||
|
||||
Config.prototype.loadWebServerConfigFile = function() {
|
||||
var configObject = {
|
||||
"enabled": true, "host": "localhost", "port": 8000
|
||||
"enabled": true, "host": "localhost", "port": 8000, "enableCatchAll": true
|
||||
};
|
||||
|
||||
let configFilePath = this._getFileOrOject(this.configDir, 'webserver', 'webserver');
|
||||
|
|
|
@ -15,10 +15,11 @@ 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({logger: this.logger, host: this.host, port: this.port, events: this.events});
|
||||
this.server = new Server({logger: this.logger, host: this.host, port: this.port, events: this.events, plugins: this.plugins});
|
||||
this.server = new Server({logger: this.logger, host: this.host, port: this.port, events: this.events, plugins: this.plugins, enableCatchAll: this.enableCatchAl});
|
||||
|
||||
this.setServiceCheck();
|
||||
this.listenToCommands();
|
||||
|
|
|
@ -15,6 +15,7 @@ class Server {
|
|||
this.hostname = options.host || 'localhost';
|
||||
this.logger = options.logger;
|
||||
this.plugins = options.plugins;
|
||||
this.enableCatchAll = options.enableCatchAll;
|
||||
}
|
||||
|
||||
start(callback) {
|
||||
|
@ -31,23 +32,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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue