set-yoho-data.js
1010 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
* 设置 YOHO 数据
* @author: 赵彪<bill.zhao@yoho.cn>
* @date: 2016/6/16
*/
'use strict';
const helpers = global.yoho.helpers;
module.exports = () => {
return (req, res, next) => {
let yoho = {
pageChannel: {}
};
const channel = req.query.channel || req.cookies._Channel || 'boys';
// 用于头部颜色控制
yoho.pageChannel[channel] = true;
// 当前频道设置
yoho.channel = channel;
// 判断请求是否来自app
yoho.isApp = req.query.app_version || req.query.appVersion;
yoho.isWechat = /micromessenger/i.test(req.get('User-Agent') || '');
Object.assign(res.locals, yoho);
Object.assign(req.yoho, yoho);
// App 内请求支持跨域
if (yoho.isApp) {
res.set('Access-Control-Allow-Origin', '*');
}
res.locals.cartUrl = helpers.urlFormat('/cart/index/index');
res.locals.showHeader = true;
next();
};
};