1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00
unleash.unleash/lib/middleware/session.js
2020-10-02 16:38:51 +02:00

24 lines
656 B
JavaScript

'use strict';
const cookieSession = require('cookie-session');
module.exports = function(config) {
const sessionMiddleware = cookieSession({
name: 'unleash-session',
keys: [config.secret],
maxAge: config.sessionAge,
secure: !!config.secureHeaders,
path: config.baseUriPath === '' ? '/' : config.baseUriPath,
});
const extendTTL = (req, res, next) => {
// Updates active sessions every hour
req.session.nowInHours = Math.floor(Date.now() / 3600e3);
next();
};
return (req, res, next) => {
sessionMiddleware(req, res, () => extendTTL(req, res, next));
};
};