我正在尝试使用JS了解会话和cookie 我正在使用express-session包来处理会话和cookie。问题出在我的客户端,当我使用邮递员时,cookie出现了
sessionID 92bda427-c9fd-4281-9979-a5b58b925e59
req.session Session {
cookie:
{ path: '/',
_expires: 2018-11-17T04:53:52.616Z,
originalMaxAge: 432000000,
httpOnly: false,
secure: false,
domain: 'localhost' },
__lastAccess: 1541998432616 }
req.cookies { SID: 's:92bda427-c9fd-4281-9979-
a5b58b925e59.gLHHBeXoebwvFEA3Y0d9kOwLxC6ICgkbcSPU9FMmHkQ'}
但是当我使用客户端访问相同的路径时,cookie只是返回空对象,我已经检查了一些stackoverflow问题,有人说要更改安全性:false和httpOnly:false,但是它不适用于我
sessionID d5ec7773-fc1c-4aad-9dbb-6f822107a681
req.session Session {
cookie:
{ path: '/',
_expires: 2018-11-17T04:53:58.260Z,
originalMaxAge: 432000000,
httpOnly: false,
domain: 'localhost',
secure: false } }
req.cookies {}
我的快递设置
var express = require('express');
var cookieParser = require('cookie-parser');
var session = require('express-session');
var FileStore = require('session-file-store')(session);
var app = express();
app.use(cookieParser());
app.use(session({
genid: (req) => {
return uuid() // use UUIDs for session IDs
},
cookie: {
domain: 'localhost',
path: '/',
secure: false,
maxAge: 7 * 24 * 60 * 60 * 1000, // 7 days
httpOnly: false,
},
store: new FileStore(),
secret: 'some secret key',
name: 'SID',
resave: true,
saveUninitialized: true
}))