Доработки devModule

This commit is contained in:
Book Pauk
2019-01-04 18:53:14 +07:00
parent f6d19445a2
commit b3b32034c5
2 changed files with 27 additions and 14 deletions

View File

@@ -15,18 +15,28 @@ function webpackDevMiddleware(app) {
app.use(hotMiddleware(compiler, {
log: log
}));
}
function logQueries(app) {
app.use(function(req, res, next) {
const start = Date.now();
const params = (req.body ? req.body.params : '');
log(`${req.method} ${req.originalUrl} ${req.body.params}`);
log(`${req.method} ${req.originalUrl} ${JSON.stringify(req.body)}`);
res.once('finish', () => {
log(`${Date.now() - start}ms`);
});
next();
});
}
function logErrors(app) {
app.use(function(err, req, res, next) {
log(LM_ERR, err.stack);
res.status(500).send(err.stack);
});
}
module.exports = {
webpackDevMiddleware
webpackDevMiddleware,
logQueries,
logErrors
};