Showing
2 changed files
with
16 additions
and
0 deletions
@@ -78,12 +78,14 @@ const logger = require('./library/logger'); | @@ -78,12 +78,14 @@ const logger = require('./library/logger'); | ||
78 | 78 | ||
79 | // dispatcher | 79 | // dispatcher |
80 | try { | 80 | try { |
81 | + const mobileCheck = require('./doraemon/middleware/mobile-check'); | ||
81 | const user = require('./doraemon/middleware/user'); | 82 | const user = require('./doraemon/middleware/user'); |
82 | const seo = require('./doraemon/middleware/seo'); | 83 | const seo = require('./doraemon/middleware/seo'); |
83 | const setYohoData = require('./doraemon/middleware/set-yoho-data'); | 84 | const setYohoData = require('./doraemon/middleware/set-yoho-data'); |
84 | const errorHanlder = require('./doraemon/middleware/error-handler'); | 85 | const errorHanlder = require('./doraemon/middleware/error-handler'); |
85 | 86 | ||
86 | // YOHO 前置中间件 | 87 | // YOHO 前置中间件 |
88 | + app.use(mobileCheck()); | ||
87 | app.use(setYohoData()); | 89 | app.use(setYohoData()); |
88 | app.use(user()); | 90 | app.use(user()); |
89 | app.use(seo()); | 91 | app.use(seo()); |
doraemon/middleware/mobile-check.js
0 → 100644
1 | +/** | ||
2 | + * 手机访问检测 | ||
3 | + */ | ||
4 | +'use strict'; | ||
5 | +module.exports = () => { | ||
6 | + return (req, res, next) => { | ||
7 | + let isMobile = /(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.test(req.get('user-agent')); // eslint-disable-line | ||
8 | + | ||
9 | + if (isMobile) { | ||
10 | + return res.redirect(`//m.yohobuy.com${req.url}`); | ||
11 | + } | ||
12 | + next(); | ||
13 | + }; | ||
14 | +}; |
-
Please register or login to post a comment