Merge branch 'release/1.0' of git.yoho.cn:fe/yohobuy-node into release/1.0
Showing
3 changed files
with
20 additions
and
2 deletions
@@ -17,8 +17,8 @@ const path = require('path'); | @@ -17,8 +17,8 @@ const path = require('path'); | ||
17 | const bodyParser = require('body-parser'); | 17 | const bodyParser = require('body-parser'); |
18 | const cookieParser = require('cookie-parser'); | 18 | const cookieParser = require('cookie-parser'); |
19 | const favicon = require('serve-favicon'); | 19 | const favicon = require('serve-favicon'); |
20 | -const session = require('yoho-express-session'); | ||
21 | -const memcached = require('yoho-connect-memcached'); | 20 | +const session = require('express-session'); |
21 | +const memcached = require('connect-memcached'); | ||
22 | const hbs = require('express-handlebars'); | 22 | const hbs = require('express-handlebars'); |
23 | const pkg = require('./package.json'); | 23 | const pkg = require('./package.json'); |
24 | 24 | ||
@@ -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 | +}; |
@@ -33,9 +33,11 @@ | @@ -33,9 +33,11 @@ | ||
33 | "dependencies": { | 33 | "dependencies": { |
34 | "bluebird": "^3.4.0", | 34 | "bluebird": "^3.4.0", |
35 | "body-parser": "^1.15.0", | 35 | "body-parser": "^1.15.0", |
36 | + "connect-memcached": "^0.2.0", | ||
36 | "cookie-parser": "^1.4.3", | 37 | "cookie-parser": "^1.4.3", |
37 | "express": "^4.13.1", | 38 | "express": "^4.13.1", |
38 | "express-handlebars": "^3.0.0", | 39 | "express-handlebars": "^3.0.0", |
40 | + "express-session": "^1.13.0", | ||
39 | "influxdb-winston": "^1.0.1", | 41 | "influxdb-winston": "^1.0.1", |
40 | "lodash": "^4.13.1", | 42 | "lodash": "^4.13.1", |
41 | "md5": "^2.1.0", | 43 | "md5": "^2.1.0", |
-
Please register or login to post a comment