before.js
582 Bytes
/**
* 设置 YOHO 数据
* @author: feng.chen<feng.chen@yoho.cn>
* @date: 2017/04/13
*/
const _ = require('lodash');
const util = require('../common/util');
module.exports = (req, res, next) => {
let yoho = {
};
req.yoho = {};
req.user = {};
// IP 地址
yoho.clientIp = util.getClientIp(req);
if (req.session && _.isNumber(req.session.LOGIN_UID)) {
req.user.uid = req.session.LOGIN_UID;
let userData = _.get(req.session, 'USER', {});
_.merge(req.user, userData);
}
Object.assign(req.yoho, yoho);
next();
};