我无法使用快速会话在不同路由器之间保持会话。这是我的app.js
const express = require('express');
const myRoutes = require('./routes/my-route');
const app = express();
const session = require('express-session');
app.use(session({
secret: 'SECRET',
cookie: {maxAge: 60*60*1000, httpOnly: true, secure: false},
resave: false,
saveUninitialized: true,
}));
app.use('/my-routes', myRoutes);
app.use('/submit', function(req, res, next) {
req.session.info = req.body.info;
});
对/submit
的任何调用都可以正常工作,并保持会话。但是当我尝试使用/my-routes/<route>
调用任何内容时,会创建一个新的cookie并重置会话。
在任何电话会议之前,这就是会议的样子
{
"cookie": {
"originalMaxAge":3600000,
"expires":"2018-06-08T17:51:37.229Z",
"secure":false,
"httpOnly":true,
"path":"/"
}
}
只需拨打/submit
{
"cookie": {
"originalMaxAge":3600000,
"expires":"2018-06-08T17:51:37.229Z",
"secure":false,
"httpOnly":true,
"path":"/"
},
"info": "thing"
}
然后,当我在/my-routes/<route>
{
"cookie": {
"originalMaxAge":3600000,
"expires":"2018-06-08T17:51:37.446Z",
"secure":false,
"httpOnly":true,
"path":"/"
}
}
看起来因为新的过期而重置了cookie。
这就是我调用ajax的方式
$.ajax({
type: 'POST',
url: '/submit',
data: data,
dataType: 'json',
success: function(data) {
window.location.href = '/index.html';
},
});