2017-11-16 15:41:33 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const cookieSession = require('cookie-session');
|
|
|
|
|
|
|
|
module.exports = function(config) {
|
2020-10-02 16:32:05 +02:00
|
|
|
const sessionMiddleware = cookieSession({
|
2017-11-16 15:41:33 +01:00
|
|
|
name: 'unleash-session',
|
|
|
|
keys: [config.secret],
|
|
|
|
maxAge: config.sessionAge,
|
2020-10-02 16:38:51 +02:00
|
|
|
secure: !!config.secureHeaders,
|
2019-04-28 12:30:39 +02:00
|
|
|
path: config.baseUriPath === '' ? '/' : config.baseUriPath,
|
2017-11-16 15:41:33 +01:00
|
|
|
});
|
2020-10-02 16:32:05 +02:00
|
|
|
|
|
|
|
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));
|
|
|
|
};
|
2017-11-16 15:41:33 +01:00
|
|
|
};
|