ensure dont overwrite data in copy from req.params to res.locals

This commit is contained in:
Simon Martín 2017-10-20 17:21:55 +02:00
parent 5645cd16b3
commit c0df0d12c6
2 changed files with 1 additions and 7 deletions

View File

@ -1,7 +1,7 @@
const _ = require('underscore');
module.exports = function localsMiddleware(req, res, next) {
_.extend(res.locals, req.params);
_.defaults(res.locals, req.params);
next();
};

View File

@ -4,11 +4,5 @@ var cdbRequest = new CdbRequest();
module.exports = function userMiddleware(req, res, next) {
res.locals.user = cdbRequest.userByReq(req);
// avoid a req.params.user equals to undefined
// overwrites res.locals.user
if(!req.params.user) {
delete req.params.user;
}
next();
};