-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsession.js
48 lines (40 loc) · 1.4 KB
/
session.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
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
Manage authentication.
Read the docs:
https://github.com/expressjs/session
https://github.com/chill117/express-mysql-session
*/
var session = require("express-session");
var MySQLSessionStore = require('express-mysql-session')(session);
var app = require('./app.js');
var config = require('./config.js');
var database = require('./database.js');
app.set('trust proxy', 1); // trust first proxy, for secure cookie
// set up a session middleware and export it
module.exports = session({
secret: config.debug !== true ? Math.random().toString(36) : 'abc123',
resave: false,
saveUninitialized: false,
unset: 'destroy',
cookie: { path: '/', httpOnly: true, secure: false },
name: 'PHPSESSID', // deception
store: new MySQLSessionStore({
// How frequently expired sessions will be cleared; milliseconds:
checkExpirationInterval: 900000, // 15*60*1000 (15 minute)
// The maximum age of a valid session; milliseconds:
expiration: 86400000, // 24*60*60*1000 (a day)
// Whether or not to create the sessions database table, if one does not already exist:
createDatabaseTable: true,
// Whether or not to end the database connection when the store is closed:
endConnectionOnClose: false, // since it's from the global pool
//charset: 'utf8mb4_bin',
schema: {
tableName: 'sessions',
columnNames: {
session_id: 'session_id',
expires: 'expires',
data: 'data'
}
},
}, database),
});