Authored by yyq

not need refer

... ... @@ -6,7 +6,13 @@ const querystring = require('querystring');
module.exports = () => {
return (req, res, next) => {
if (!req.xhr && req.isMobile) {
if (req.xhr) {
return next();
}
if (req.noRefer) {
res.locals.mobileRefer = '';
} else if (req.isMobile) {
return res.redirect(req.mobileUrl || res.locals.mobileRefer ||
`//m.yohobuy.com${req.url}?${querystring.stringify(req.query)}`);
}
... ...
... ... @@ -26,9 +26,12 @@ const ptm = {
// 领券中心
'/coupon/index': '/coupon/floor?title=领券中心&code=b78b32ed81b18dde8ac84fd33602b88b'
};
const notNeedReferMap = [
/^\/special\/(\d+)_/
];
const genderMap = {
boys: '1,3',
girls: '2,3',
... ... @@ -47,12 +50,6 @@ module.exports = () => {
if (ptm.hasOwnProperty(url)) {
data.mobileRefer = `//${domain}${ptm[url]}`;
} else if (url === '/product/list/index') {
data.mobileRefer = `//list.${domain}`;
} else if (url === '/product/index/brand') {
data.mobileRefer = `//${req.query.domain}.${domain}`;
} else if (url === '/product/search/index') {
data.mobileRefer = `//search.${domain}?${queryString.stringify(req.query)}`;
} else if (url === '/guang/') {
req.query.gender = genderMap[req.query.channel];
_.unset(req.query, 'channel');
... ... @@ -61,6 +58,12 @@ module.exports = () => {
data.mobileRefer = url.replace(proRegNew, `//${domain}/product/$1.html$2`);
}
// 设置不需要跳转页面
req.noRefer = _.find(notNeedReferMap, rule => {
return (_.isRegExp(rule) && rule.test(req.url) ||
(_.isString(rule) && _.isEqual(req.url, rule)));
});
Object.assign(res.locals, data);
}
next();
... ...