set-yoho-data.js 823 Bytes
/**
 * 设置 YOHO 数据
 * @author: 赵彪<bill.zhao@yoho.cn>
 * @date: 2016/6/16
 */

'use strict';

const CHANNEL = {
    boys: 'boys',
    girls: 'girls',
    kids: 'kids',
    lifestyle: 'lifestyle'
};

module.exports = () => {
    return (req, res, next) => {
        let yoho = {
            pageChannel: {}
        };

        const channel = CHANNEL[req.query.channel || req.cookies._Channel] || CHANNEL.boys;

        if (req.query.channel) {
            req.query.channel = channel;
        }

        // 用于头部颜色控制
        yoho.pageChannel[channel] = true;

        // 当前频道设置
        yoho.channel = channel;

        yoho.isApp = req.query.app_version || req.query.appVersion;

        Object.assign(res.locals, yoho);
        Object.assign(req.yoho, yoho);
        next();
    };
};