Authored by 周少峰

Merge branch 'hotfix/mobile' into release/hbs

... ... @@ -81,6 +81,7 @@ const logger = global.yoho.logger;
// dispatcher
try {
const subDomain = require('./doraemon/middleware/sub-domain');
const mobileRefer = require('./doraemon/middleware/mobile-refer');
const itemNameHandler = require('./doraemon/middleware/item-name-handler');
const mobileCheck = require('./doraemon/middleware/mobile-check');
const user = require('./doraemon/middleware/user');
... ... @@ -92,6 +93,7 @@ try {
// YOHO 前置中间件
app.use(subDomain());
app.use(mobileRefer());
app.use(itemNameHandler);
app.use(mobileCheck());
app.use(setYohoData());
... ...
/**
* page cache 前端js跳转url中间件
*/
'use strict';
const _ = require('lodash');
const querystring = require('querystring');
const ptm = {
// 首页
'/': '',
'/woman': '/girls',
'/kids': '/kids',
'/lifestyle': '/lifestyle',
// 登录注册
'/signin.html': '/signin.htm',
'/reg.html': '/passport/reg/index',
'/passport/back/index': '/passport/back/mobile',
// 列表
'/product/list/new': '/product/new',
// 品牌列表
'/brands': '/brands',
// 领券中心
'/coupon/index': '/coupon/floor?title=领券中心&code=b78b32ed81b18dde8ac84fd33602b88b'
};
module.exports = () => {
return (req, res, next) => {
let domain = 'm.yohobuy.com';
let proReg = /^\/product\/pro/,
guangReg = /^\/guang/,
guangDetailReg = /.html$/,
qsReg = /\?/;
if (!req.xhr) {
let url = _.head(_.split(req.url, '?'));
let data = {};
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}`;
} else if (guangReg.test(url)) {
data.mobileRefer = `//guang.${domain}`;
if (guangDetailReg.test(url)) {
data.mobileRefer += url.replace(/\/guang\/detail\/([\d]+).html/, '/info/index?id=$1');
} else if (url === '/guang/Index/editor') {
data.mobileRefer += `/author/index?id=${req.query.author_id}`;
}
} else if (proReg.test(url)) {
data.mobileRefer = `//${domain}${url}`;
}
if (!_.isEmpty(req.query) && !qsReg.test(data.mobileRefer)) {
data.mobileRefer += `?${querystring.stringify(req.query)}`;
}
Object.assign(res.locals, data);
}
next();
};
};
... ...
... ... @@ -21,6 +21,10 @@
{{/if}}
</head>
<body>
{{#if mobileRefer}}
<input type="hidden" id="m-refer" value="{{mobileRefer}}">
{{/if}}
{{> header}}
{{> common/simple-header}}
{{#if pageErr}}
... ...
... ... @@ -94,6 +94,15 @@ function getShoppingKey() {
return JSON.parse(c).k;
}
// page cache改造-前端移动端检测
(function() {
var mrefer = $('#m-refer').val();
if (mrefer && window.navigator.userAgent.match(/(nokia|iphone|android|ipad|motorola|^mot\-|softbank|foma|docomo|kddi|up\.browser|up\.link|htc|dopod|blazer|netfront|helio|hosin|huawei|novarra|CoolPad|webos|techfaith|palmsource|blackberry|alcatel|amoi|ktouch|nexian|samsung|^sam\-|s[cg]h|^lge|ericsson|philips|sagem|wellcom|bunjalloo|maui|symbian|smartphone|midp|wap|phone|windows ce|iemobile|^spice|^bird|^zte\-|longcos|pantech|gionee|^sie\-|portalmmm|jig\s browser|hiptop|^ucweb|^benq|haier|^lct|opera\s*mobi|opera\*mini|320x320|240x320|176x220)/i)) { // eslint-disable-line
window.location = mrefer;
}
}());
// YAS统计代码
(function(w, d, s, j, f) {
var a = d.createElement(s);
... ...