before.js 691 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 && req.session.LOGIN_UID) {
        req.user.uid = req.session.LOGIN_UID;
        _.merge(req.user, _.get(req.session, 'USER', {}));
    }

    // 当前选择的店铺
    if (req.session && req.session.CURRENT_SHOP) {
        _.merge(req.user, {currentShop: req.session.CURRENT_SHOP});
    }

    Object.assign(req.yoho, yoho);

    next();
};