我无法终生解决为什么我的会话或Cookie无法在网址中持续存在的原因
表达
app.use(session({
secret: 'somethign secrect',
resave: true,
saveUninitialized: true,
cookie: {
path: '/',
domain: config.cookieDomain,
httpOnly: true,
secure: false,
maxAge: null,
cookie: { domain:config.cookieDomain}
},
rolling: true
}));
网址/ auth
//Store cookies for 1 hour
console.info(options.req.session); //output 1
options.req.session.HUTBER = 'JAMIE';
console.info(options.req.session); //output 2
网址/ auth /回调**
console.info('auth', req.session); //output 3
终端输出
//Output 1
@40000000576c2d6d061dbe14 Session {
@40000000576c2d6d061dc1fc cookie:
@40000000576c2d6d061dc1fc { path: '/',
@40000000576c2d6d061dc1fc _expires: null,
@40000000576c2d6d061dc5e4 originalMaxAge: null,
@40000000576c2d6d061dc5e4 httpOnly: true,
@40000000576c2d6d061dc9cc domain: 'mysite.co.uk',
@40000000576c2d6d061dc9cc secure: false,
@40000000576c2d6d061dcdb4 cookie: { domain: 'mysite.co.uk' } } }
//Output 2
@40000000576c2d6d0624e61c Session {
@40000000576c2d6d0624ea04 cookie:
@40000000576c2d6d0624ea04 { path: '/',
@40000000576c2d6d0624edec _expires: null,
@40000000576c2d6d0624edec originalMaxAge: null,
@40000000576c2d6d0624f1d4 httpOnly: true,
@40000000576c2d6d0624f1d4 domain: 'mysite.co.uk',
@40000000576c2d6d0624f5bc secure: false,
@40000000576c2d6d0624f5bc cookie: { domain: 'mysite.co.uk' } },
@40000000576c2d6d0624f9a4 HUTBER: 'JAMIE' }
//Output 3
@40000000576c2d7c14dfd57c auth Session {
@40000000576c2d7c14dfdd4c cookie:
@40000000576c2d7c14dfdd4c { path: '/',
@40000000576c2d7c14dfe134 _expires: null,
@40000000576c2d7c14dfe134 originalMaxAge: null,
@40000000576c2d7c14dfe51c httpOnly: true,
@40000000576c2d7c14dfe51c domain: 'mysite.co.uk',
@40000000576c2d7c14dfe904 secure: false,
@40000000576c2d7c14dfecec cookie: { domain: 'mysite.co.uk' } } }
如何获得两条路线之间的数据?
最佳答案
首先,您将默认会话存储用于会话中间件。默认会话存储将您的会话信息存储在内存中,仅适用于开发和测试目的。如果您正在使用多个应用程序实例和一个负载平衡器(通常在生产环境中期望),则默认会话存储将对您不起作用。建议您使用connect-redis之类的其他商店,或将会话信息保存到专门商店的其他商店。
关于javascript - Node.js session 在生产中不持久,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37999520/