Answer the question
In order to leave comments, you need to log in
How does a session work in express?
I read about the express-session session, did it according to the example, but why from the site if you make a request every time a new session, but from the postman it is the same?
// Настраиваем сессию
app.use(session({
secret: manifest.session.secret, // Используется для подписи файлов cookie, связанных с идентификатором сеанса
store: new RedisStore({client: redis.createClient(manifest.redis.port, manifest.redis.ip)}), // (использовать сессию хранения Redis)
saveUninitialized: true, // Следует ли автоматически сохранять неинициализированные сеансы, рекомендуется false
resave: true, // Следует ли повторно сохранять сессию каждый раз, рекомендуется false
cookie: {
maxAge: 86400000 // 24 часа в мс
}
}));
// Проверяем, нормальная ли сессия
app.use( function (req, res, next) {
if (!req.session)
{
return next( new Error( 'Error session' ) )
}
console.log("\n===СЕССИЯ\n", req.sessionID, "\n===\n");
next(); // Следующее промежуточное ПО
});
Answer the question
In order to leave comments, you need to log in
express-session
keeps track of the session via a cookie. Perhaps you are not sending cookies that you previously received from the server and therefore get a new session each time.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question