mirror of https://github.com/embarklabs/embark.git
Merge pull request #795 from embark-framework/bug_fix/webserver-config-change
Watch webserver config and restart it
This commit is contained in:
commit
833fcef22a
|
@ -328,7 +328,7 @@ Config.prototype.loadWebServerConfigFile = function() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.webServerConfig) {
|
if (this.webServerConfig) {
|
||||||
// cli falgs to `embark run` should override configFile and defaults (configObject)
|
// cli flags to `embark run` should override configFile and defaults (configObject)
|
||||||
this.webServerConfig = utils.recursiveMerge(webServerConfig, this.webServerConfig);
|
this.webServerConfig = utils.recursiveMerge(webServerConfig, this.webServerConfig);
|
||||||
} else {
|
} else {
|
||||||
this.webServerConfig = webServerConfig;
|
this.webServerConfig = webServerConfig;
|
||||||
|
|
|
@ -32,6 +32,26 @@ class WebServer {
|
||||||
port: this.port
|
port: this.port
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.events.on('webserver:config:change', () => {
|
||||||
|
this.embark.config.webServerConfig = null;
|
||||||
|
this.embark.config.loadWebServerConfigFile();
|
||||||
|
this.webServerConfig = this.embark.config.webServerConfig;
|
||||||
|
this.host = this.webServerConfig.host;
|
||||||
|
this.port = this.webServerConfig.port;
|
||||||
|
this.server.host = this.host;
|
||||||
|
this.server.port = this.port;
|
||||||
|
|
||||||
|
this.testPort(() => {
|
||||||
|
this.server.stop((_err) => {
|
||||||
|
this.server.start((_err, message, port) => {
|
||||||
|
this.logger.info(message);
|
||||||
|
this.port = port;
|
||||||
|
this.events.request('open-browser', () => {});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
this.testPort(() => {
|
this.testPort(() => {
|
||||||
this.listenToCommands();
|
this.listenToCommands();
|
||||||
this.registerConsoleCommands();
|
this.registerConsoleCommands();
|
||||||
|
|
|
@ -26,8 +26,12 @@ class Watch {
|
||||||
self.logger.trace('ready to watch contract changes');
|
self.logger.trace('ready to watch contract changes');
|
||||||
});
|
});
|
||||||
|
|
||||||
this.watchConfigs(embarkConfig, function () {
|
this.watchContractConfig(embarkConfig, function () {
|
||||||
self.logger.trace('ready to watch config changes');
|
self.logger.trace('ready to watch contract config changes');
|
||||||
|
});
|
||||||
|
|
||||||
|
this.watchWebserverConfig(embarkConfig, function () {
|
||||||
|
self.logger.trace('ready to watch webserver config changes');
|
||||||
});
|
});
|
||||||
|
|
||||||
this.logger.info(__("ready to watch file changes"));
|
this.logger.info(__("ready to watch file changes"));
|
||||||
|
@ -96,19 +100,45 @@ class Watch {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
watchConfigs(embarkConfig, callback) {
|
watchWebserverConfig(embarkConfig, callback) {
|
||||||
let self = this;
|
let self = this;
|
||||||
let contractsConfig;
|
let webserverConfig;
|
||||||
if (typeof embarkConfig.config === 'object' || embarkConfig.config.contracts) {
|
if (typeof embarkConfig.config === 'object') {
|
||||||
contractsConfig = embarkConfig.config.contracts;
|
if (!embarkConfig.config.webserver) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
webserverConfig = embarkConfig.config.webserver;
|
||||||
} else {
|
} else {
|
||||||
let contractsFolder = embarkConfig.config.replace(/\\/g, '/');
|
let contractsFolder = embarkConfig.config.replace(/\\/g, '/');
|
||||||
if (contractsFolder.charAt(contractsFolder.length - 1) !== '/') {
|
if (contractsFolder.charAt(contractsFolder.length - 1) !== '/') {
|
||||||
contractsFolder += '/';
|
contractsFolder += '/';
|
||||||
}
|
}
|
||||||
contractsConfig = [`${contractsFolder}**/contracts.json`, `${contractsFolder}**/contracts.js`];
|
webserverConfig = [`${contractsFolder}**/webserver.json`, `${contractsFolder}**/webserver.js`];
|
||||||
}
|
}
|
||||||
this.watchFiles(contractsConfig,
|
this.watchFiles(webserverConfig,
|
||||||
|
function (eventName, path) {
|
||||||
|
self.logger.info(`${eventName}: ${path}`);
|
||||||
|
self.events.emit('webserver:config:change', 'config', path);
|
||||||
|
},
|
||||||
|
function () {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
watchContractConfig(embarkConfig, callback) {
|
||||||
|
let self = this;
|
||||||
|
let contractConfig;
|
||||||
|
if (typeof embarkConfig.config === 'object' || embarkConfig.config.contracts) {
|
||||||
|
contractConfig = embarkConfig.config.contracts;
|
||||||
|
} else {
|
||||||
|
let contractsFolder = embarkConfig.config.replace(/\\/g, '/');
|
||||||
|
if (contractsFolder.charAt(contractsFolder.length - 1) !== '/') {
|
||||||
|
contractsFolder += '/';
|
||||||
|
}
|
||||||
|
contractConfig = [`${contractsFolder}**/contracts.json`, `${contractsFolder}**/contracts.js`];
|
||||||
|
}
|
||||||
|
this.watchFiles(contractConfig,
|
||||||
function (eventName, path) {
|
function (eventName, path) {
|
||||||
self.logger.info(`${eventName}: ${path}`);
|
self.logger.info(`${eventName}: ${path}`);
|
||||||
self.events.emit('file-' + eventName, 'config', path);
|
self.events.emit('file-' + eventName, 'config', path);
|
||||||
|
|
Loading…
Reference in New Issue