Authored by yyq

not need refer

@@ -6,7 +6,13 @@ const querystring = require('querystring'); @@ -6,7 +6,13 @@ const querystring = require('querystring');
6 6
7 module.exports = () => { 7 module.exports = () => {
8 return (req, res, next) => { 8 return (req, res, next) => {
9 - if (!req.xhr && req.isMobile) { 9 + if (req.xhr) {
  10 + return next();
  11 + }
  12 +
  13 + if (req.noRefer) {
  14 + res.locals.mobileRefer = '';
  15 + } else if (req.isMobile) {
10 return res.redirect(req.mobileUrl || res.locals.mobileRefer || 16 return res.redirect(req.mobileUrl || res.locals.mobileRefer ||
11 `//m.yohobuy.com${req.url}?${querystring.stringify(req.query)}`); 17 `//m.yohobuy.com${req.url}?${querystring.stringify(req.query)}`);
12 } 18 }
@@ -26,9 +26,12 @@ const ptm = { @@ -26,9 +26,12 @@ const ptm = {
26 26
27 // 领券中心 27 // 领券中心
28 '/coupon/index': '/coupon/floor?title=领券中心&code=b78b32ed81b18dde8ac84fd33602b88b' 28 '/coupon/index': '/coupon/floor?title=领券中心&code=b78b32ed81b18dde8ac84fd33602b88b'
29 -  
30 }; 29 };
31 30
  31 +const notNeedReferMap = [
  32 + /^\/special\/(\d+)_/
  33 +];
  34 +
32 const genderMap = { 35 const genderMap = {
33 boys: '1,3', 36 boys: '1,3',
34 girls: '2,3', 37 girls: '2,3',
@@ -47,12 +50,6 @@ module.exports = () => { @@ -47,12 +50,6 @@ module.exports = () => {
47 50
48 if (ptm.hasOwnProperty(url)) { 51 if (ptm.hasOwnProperty(url)) {
49 data.mobileRefer = `//${domain}${ptm[url]}`; 52 data.mobileRefer = `//${domain}${ptm[url]}`;
50 - } else if (url === '/product/list/index') {  
51 - data.mobileRefer = `//list.${domain}`;  
52 - } else if (url === '/product/index/brand') {  
53 - data.mobileRefer = `//${req.query.domain}.${domain}`;  
54 - } else if (url === '/product/search/index') {  
55 - data.mobileRefer = `//search.${domain}?${queryString.stringify(req.query)}`;  
56 } else if (url === '/guang/') { 53 } else if (url === '/guang/') {
57 req.query.gender = genderMap[req.query.channel]; 54 req.query.gender = genderMap[req.query.channel];
58 _.unset(req.query, 'channel'); 55 _.unset(req.query, 'channel');
@@ -61,6 +58,12 @@ module.exports = () => { @@ -61,6 +58,12 @@ module.exports = () => {
61 data.mobileRefer = url.replace(proRegNew, `//${domain}/product/$1.html$2`); 58 data.mobileRefer = url.replace(proRegNew, `//${domain}/product/$1.html$2`);
62 } 59 }
63 60
  61 + // 设置不需要跳转页面
  62 + req.noRefer = _.find(notNeedReferMap, rule => {
  63 + return (_.isRegExp(rule) && rule.test(req.url) ||
  64 + (_.isString(rule) && _.isEqual(req.url, rule)));
  65 + });
  66 +
64 Object.assign(res.locals, data); 67 Object.assign(res.locals, data);
65 } 68 }
66 next(); 69 next();