set-yoho-data.js
855 Bytes
/**
* 设置 YOHO 数据
* @author: 赵彪<bill.zhao@yoho.cn>
* @date: 2016/6/16
*/
'use strict';
module.exports = () => {
return (req, res, next) => {
let yoho = {
pageChannel: {},
yohoTitle: 'Yoho!BLK'
};
const channel = req.query.channel || req.cookies._Channel || 'men';
// 用于头部颜色控制
yoho.pageChannel[channel] = true;
// 当前频道设置
yoho.channel = channel;
// 判断请求是否来自app
let userAgent = req.get('User-Agent');
yoho.isApp = /yh_blk/i.test(req.get('User-Agent'));
yoho.isiOS = /\(i[^;]+;( U;)? CPU.+Mac OS X/i.test(userAgent);
yoho.isAndroid = /Android/i.test(userAgent);
Object.assign(res.locals, yoho);
Object.assign(req.yoho, yoho);
next();
};
};