mirror of https://github.com/embarklabs/embark.git
added webserver logging
This commit is contained in:
parent
51b2cce0ea
commit
08c140b035
|
@ -103,6 +103,8 @@ class WebServer {
|
|||
this.events.setCommandHandler('open-browser', (cb) => this.openBrowser(cb));
|
||||
this.events.setCommandHandler('start-webserver', (cb) => this.server.start(cb));
|
||||
this.events.setCommandHandler('stop-webserver', (cb) => this.server.stop(cb));
|
||||
this.events.setCommandHandler('logs:webserver:turnOn', (cb) => this.server.enableLogging(cb));
|
||||
this.events.setCommandHandler('logs:webserver:turnOff', (cb) => this.server.disableLogging(cb));
|
||||
}
|
||||
|
||||
registerConsoleCommands() {
|
||||
|
@ -127,6 +129,20 @@ class WebServer {
|
|||
process: (cb) => self.events.request('open-browser', cb)
|
||||
};
|
||||
});
|
||||
|
||||
self.embark.registerConsoleCommand((cmd, _options) => {
|
||||
return {
|
||||
match: () => cmd === 'log webserver on',
|
||||
process: (cb) => self.events.request('logs:webserver:turnOn', cb)
|
||||
};
|
||||
});
|
||||
|
||||
self.embark.registerConsoleCommand((cmd, _options) => {
|
||||
return {
|
||||
match: () => cmd === 'log webserver off',
|
||||
process: (cb) => self.events.request('logs:webserver:turnOff', cb)
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
buildPlaceholderPage(cb) {
|
||||
|
|
|
@ -15,6 +15,17 @@ class Server {
|
|||
this.isFirstStart = true;
|
||||
this.opened = false;
|
||||
this.openBrowser = options.openBrowser;
|
||||
this.logging = false;
|
||||
}
|
||||
|
||||
enableLogging(callback) {
|
||||
this.logging = true;
|
||||
return callback(null, __("Enabled Webserver Logs"));
|
||||
}
|
||||
|
||||
disableLogging(callback) {
|
||||
this.logging = false;
|
||||
return callback(null, __("Disabled Webserver Logs"));
|
||||
}
|
||||
|
||||
start(callback) {
|
||||
|
@ -32,7 +43,16 @@ class Server {
|
|||
|
||||
this.app = express();
|
||||
const expressWs = expressWebSocket(this.app);
|
||||
|
||||
|
||||
// Assign Logging Function
|
||||
this.app.use(function(req, res, next) {
|
||||
if (self.logging) {
|
||||
if (!req.headers.upgrade) {
|
||||
console.log('Webserver> ' + req.method + " " + req.originalUrl);
|
||||
}
|
||||
}
|
||||
next();
|
||||
});
|
||||
this.app.use(main);
|
||||
this.app.use('/coverage', coverage);
|
||||
this.app.use(coverageStyle);
|
||||
|
|
Loading…
Reference in New Issue