-
Notifications
You must be signed in to change notification settings - Fork 128
/
Copy pathsession.config.js
35 lines (27 loc) · 1.09 KB
/
session.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
'use strict';
var session = require('express-session');
var AzureTablesStoreFactory = require('connect-azuretables')(session);
function configSessions(app) {
var cookieOptions = { maxAge: 3600000 };
var logger = require('../config/loggers.config').logger;
if (process.env.NODE_ENV && process.env.NODE_ENV != 'development') {
cookieOptions.secure = true;
} else {
logger.error({ security: true }, 'secure session cookie flag was false - should only happen in dev environments');
}
var sessionOptions = {
secret: process.env.SESSION_SIGNING_KEY,
resave: false,
saveUninitialized: false,
rolling: true,
cookie: cookieOptions
};
if (process.env.SESSION_STORE != 'local') {
sessionOptions.store = AzureTablesStoreFactory.create({ errorLogger: logger.error.bind(logger) });
} else {
//use in-memory session store
logger.error({ security: true }, 'local session store used - should only happen in dev environments');
}
app.use(session(sessionOptions));
}
module.exports = configSessions;