Merge branch 'release/4.6' of git.yoho.cn:fe/yohobuy-node into release/4.6
Showing
19 changed files
with
32 additions
and
22 deletions
@@ -19,22 +19,19 @@ const cookieParser = require('cookie-parser'); | @@ -19,22 +19,19 @@ const cookieParser = require('cookie-parser'); | ||
19 | const favicon = require('serve-favicon'); | 19 | const favicon = require('serve-favicon'); |
20 | const session = require('yoho-express-session'); | 20 | const session = require('yoho-express-session'); |
21 | const memcached = require('yoho-connect-memcached'); | 21 | const memcached = require('yoho-connect-memcached'); |
22 | -const uuid = require('uuid'); | ||
23 | const _ = require('lodash'); | 22 | const _ = require('lodash'); |
24 | const pkg = require('./package.json'); | 23 | const pkg = require('./package.json'); |
24 | +const cookie = require('./library/cookie'); | ||
25 | 25 | ||
26 | const app = express(); | 26 | const app = express(); |
27 | const MemcachedStore = memcached(session); | 27 | const MemcachedStore = memcached(session); |
28 | +const seo = require('./doraemon/middleware/seo'); | ||
28 | 29 | ||
29 | // 指定libray目录 | 30 | // 指定libray目录 |
30 | global.library = path.resolve('./library'); | 31 | global.library = path.resolve('./library'); |
31 | global.middleware = path.resolve('./doraemon/middleware'); | 32 | global.middleware = path.resolve('./doraemon/middleware'); |
32 | global.utils = path.resolve('./utils'); | 33 | global.utils = path.resolve('./utils'); |
33 | 34 | ||
34 | -const seo = require(`${global.middleware}/seo`); | ||
35 | - | ||
36 | - | ||
37 | - | ||
38 | // 向模板注入变量 | 35 | // 向模板注入变量 |
39 | app.locals.devEnv = app.get('env') === 'development'; | 36 | app.locals.devEnv = app.get('env') === 'development'; |
40 | app.locals.version = pkg.version; | 37 | app.locals.version = pkg.version; |
@@ -47,23 +44,21 @@ app.use(express.static(path.join(__dirname, 'public'))); | @@ -47,23 +44,21 @@ app.use(express.static(path.join(__dirname, 'public'))); | ||
47 | app.use(bodyParser.json()); | 44 | app.use(bodyParser.json()); |
48 | app.use(bodyParser.urlencoded({extended: false})); | 45 | app.use(bodyParser.urlencoded({extended: false})); |
49 | app.use(cookieParser()); | 46 | app.use(cookieParser()); |
47 | + | ||
50 | app.use(session({ | 48 | app.use(session({ |
51 | proxy: true, | 49 | proxy: true, |
52 | resave: false, | 50 | resave: false, |
53 | saveUninitialized: true, | 51 | saveUninitialized: true, |
54 | unset: 'destroy', | 52 | unset: 'destroy', |
55 | - secret: 'nothing', // 兼容 PHP SESSION,sessionID 不加密 | ||
56 | - name: 'PHPSESSID', // 兼容 PHP SESSION | ||
57 | - genid: () => { | ||
58 | - return uuid.v4(); // 兼容 PHP SESSION | ||
59 | - }, | 53 | + secret: '82dd7e724f2c6870472c89dfa43cf48d', |
54 | + name: 'yohobuy_session', | ||
60 | cookie: { | 55 | cookie: { |
61 | - domain: 'yohobuy.com' | 56 | + domain: 'yohobuy.com', |
57 | + httpOnly: false | ||
62 | }, | 58 | }, |
63 | store: new MemcachedStore({ | 59 | store: new MemcachedStore({ |
64 | hosts: config.memcache.session, | 60 | hosts: config.memcache.session, |
65 | - prefix: 'qinsessionsession:', // 兼容 PHP SESSION | ||
66 | - key: 'yohobuy_session' // 兼容 PHP SESSION | 61 | + prefix: 'yohobuy_session:' |
67 | }) | 62 | }) |
68 | })); | 63 | })); |
69 | 64 | ||
@@ -75,12 +70,15 @@ app.use((req, res, next) => { | @@ -75,12 +70,15 @@ app.use((req, res, next) => { | ||
75 | req.user.uid = req.session._LOGIN_UID; | 70 | req.user.uid = req.session._LOGIN_UID; |
76 | } | 71 | } |
77 | 72 | ||
73 | + // session 没有读取到的时候,从 cookie 读取 UID | ||
74 | + if (!req.user.uid && req.cookies._UID) { | ||
75 | + req.user.uid = cookie.getUid(req); | ||
76 | + } | ||
78 | next(); | 77 | next(); |
79 | }); | 78 | }); |
80 | 79 | ||
81 | app.use(seo()); | 80 | app.use(seo()); |
82 | 81 | ||
83 | - | ||
84 | // dispatcher | 82 | // dispatcher |
85 | require('./dispatch')(app); | 83 | require('./dispatch')(app); |
86 | 84 |
@@ -59,9 +59,9 @@ if (isProduction) { | @@ -59,9 +59,9 @@ if (isProduction) { | ||
59 | service: 'http://service.yoho.yohoops.org/' | 59 | service: 'http://service.yoho.yohoops.org/' |
60 | }, | 60 | }, |
61 | memcache: { | 61 | memcache: { |
62 | - master: ['172.31.22.1:12111', '172.31.20.56:12111', '172.31.31.146:12111'], | ||
63 | - slave: ['172.31.22.1:12112', '172.31.20.56:12112', '172.31.31.146:12112'], | ||
64 | - session: ['172.31.22.1:12111', '172.31.20.56:12111', '172.31.31.146:12111'], | 62 | + master: ['memcache1.yohoops.org:12111', 'memcache2.yohoops.org:12111', 'memcache3.yohoops.org:12111'], |
63 | + slave: ['memcache1.yohoops.org:12112', 'memcache2.yohoops.org:12112', 'memcache3.yohoops.org:12112'], | ||
64 | + session: ['memcache1.yohoops.org:12111', 'memcache2.yohoops.org:12111', 'memcache3.yohoops.org:12111'], | ||
65 | timeout: 3000 | 65 | timeout: 3000 |
66 | }, | 66 | }, |
67 | useOneapm: true, | 67 | useOneapm: true, |
@@ -3,6 +3,9 @@ | @@ -3,6 +3,9 @@ | ||
3 | * @param {[object]} req | 3 | * @param {[object]} req |
4 | * @return {[string]} | 4 | * @return {[string]} |
5 | */ | 5 | */ |
6 | +'use strict'; | ||
7 | +const sign = require('./sign'); | ||
8 | + | ||
6 | exports.getUid = (req) => { | 9 | exports.getUid = (req) => { |
7 | const cookie = req.cookies._UID; | 10 | const cookie = req.cookies._UID; |
8 | let _uid = 0; | 11 | let _uid = 0; |
@@ -19,5 +22,14 @@ exports.getUid = (req) => { | @@ -19,5 +22,14 @@ exports.getUid = (req) => { | ||
19 | } | 22 | } |
20 | } | 23 | } |
21 | 24 | ||
25 | + // 校验 cookie 的 uid 有没有被修改 | ||
26 | + if (req.cookies._TOKEN !== sign.makeToken(_uid)) { | ||
27 | + _uid = 0; | ||
28 | + } | ||
29 | + | ||
22 | return _uid; | 30 | return _uid; |
23 | }; | 31 | }; |
32 | + | ||
33 | +exports.getShoppingKey = (req) => { | ||
34 | + return req.cookies['_SPK'] ? req.cookies['_SPK'] : ''; // eslint-disable-line | ||
35 | +}; |
public/.DS_Store
0 → 100644
No preview for this file type
public/css/index.css
0 → 100644
This diff could not be displayed because it is too large.
public/css/index.css.map
0 → 100644
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
@@ -25,7 +25,7 @@ const env = { | @@ -25,7 +25,7 @@ const env = { | ||
25 | 25 | ||
26 | const config = require('../package.json'); | 26 | const config = require('../package.json'); |
27 | const ftpConfig = { | 27 | const ftpConfig = { |
28 | - host: '218.94.75.50', | 28 | + host: '218.94.75.58', |
29 | user: 'php', | 29 | user: 'php', |
30 | pass: 'yoho9646' | 30 | pass: 'yoho9646' |
31 | }; | 31 | }; |
@@ -189,6 +189,7 @@ gulp.task('webpack', () => { | @@ -189,6 +189,7 @@ gulp.task('webpack', () => { | ||
189 | var proConfig = Object.assign({}, webpackConfig); | 189 | var proConfig = Object.assign({}, webpackConfig); |
190 | 190 | ||
191 | proConfig.output.path = dist.js; | 191 | proConfig.output.path = dist.js; |
192 | + proConfig.plugins = [new webpack.optimize.UglifyJsPlugin()]; | ||
192 | webpack(proConfig, (err, stats) => { | 193 | webpack(proConfig, (err, stats) => { |
193 | if (err) { | 194 | if (err) { |
194 | throw new gutil.PluginError('webpack', err); | 195 | throw new gutil.PluginError('webpack', err); |
public/img/.DS_Store
0 → 100644
No preview for this file type
public/img/channel/.DS_Store
0 → 100644
No preview for this file type
public/img/common/.DS_Store
0 → 100644
No preview for this file type
public/js/.DS_Store
0 → 100644
No preview for this file type
@@ -15,7 +15,6 @@ var homePage = $('.home-page').data('page'), | @@ -15,7 +15,6 @@ var homePage = $('.home-page').data('page'), | ||
15 | require('../common'); | 15 | require('../common'); |
16 | 16 | ||
17 | require('../plugins/slider'); | 17 | require('../plugins/slider'); |
18 | -require('../plugins/slider2'); | ||
19 | require('../plugins/logo-brand'); | 18 | require('../plugins/logo-brand'); |
20 | 19 | ||
21 | require('../plugins/accordion'); | 20 | require('../plugins/accordion'); |
@@ -558,7 +558,7 @@ | @@ -558,7 +558,7 @@ | ||
558 | line-height: 40px; | 558 | line-height: 40px; |
559 | padding-right: 46px; | 559 | padding-right: 46px; |
560 | box-sizing: border-box; | 560 | box-sizing: border-box; |
561 | - margin-right: 38px; | 561 | + margin-right: 36px; |
562 | display: inline-block; | 562 | display: inline-block; |
563 | } | 563 | } |
564 | 564 |
-
Please register or login to post a comment