Authored by 陈峰

Merge branch 'hotfix/fix-session-cookie' into 'master'

修复当memcached不可用时,会有一个cookie对象undefined的错误

修复当memcached不可用时,会有一个cookie对象undefined的错误      
![image](/uploads/09aca0cb0ca9ee700699c43ba38a2d8e/image.png)


See merge request !107
Showing 1 changed file with 14 additions and 9 deletions
... ... @@ -76,6 +76,13 @@ app.use(bodyParser.urlencoded({
app.use(cookieParser());
app.use(compression());
const sessionStore = new MemcachedStore({
hosts: config.memcache.session,
prefix: 'yohobuy_session:',
reconnect: 5000,
timeout: 1000,
retries: 0
});
app.use(memcachedSession({
proxy: true,
resave: false,
... ... @@ -87,20 +94,14 @@ app.use(memcachedSession({
domain: 'yohobuy.com',
httpOnly: false
},
store: new MemcachedStore({
hosts: config.memcache.session,
prefix: 'yohobuy_session:',
reconnect: 5000,
timeout: 1000,
retries: 0
})
store: sessionStore
}));
app.use(cookieSession({
requestKey: 'session2',
cookieName: 'yohobuy_session_cookie',
secret: '82dd7e724f2c6870472c89dfa43cf48d',
domain: config.cookieDomain
domain: 'yohobuy.com'
}));
app.use((req, res, next) => {
... ... @@ -118,6 +119,10 @@ app.use((req, res, next) => {
req.session2.sessionBack = req.session;
} else {
req.session = new memcachedSession.Session(req);
req.session.cookie = new memcachedSession.Cookie({
domain: 'yohobuy.com',
httpOnly: false
});
req.session = _.assign(req.session, req.session2.sessionBack);
}
... ... @@ -177,6 +182,6 @@ try {
}
// listener
app.listen(config.port, function() {
app.listen(config.port, function () {
logger.info('yohobuy start');
});
... ...