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
|
import expressSession from "express-session";
import sqlite from "better-sqlite3";
import sqliteStore from "better-sqlite3-session-store";
const SqliteStore = sqliteStore(expressSession);
const db = new sqlite("sessions.db", { verbose: console.log });
const secret = process.env.SESSION_SECRET || "secret";
const session = expressSession({
cookie: {
httpOnly: true,
maxAge: 1000 * 60 * 60 * 24 * 15, // 15 days
sameSite: "Strict",
secure: process.env.NODE_ENV === "production" ? true : false,
},
name: "JDMSessionId",
saveUninitialized: false,
secret: secret,
store: new SqliteStore({
client: db,
expired: {
clear: true,
intervalMs: 1000 * 60 * 60, // 60min
}
}),
resave: false,
unset: "destroy",
});
export default session;
|