(_ => { const root_path = process.cwd(); const express_session = require("express-session"); const redis = require("redis"); const RedisStore = require("connect-redis")(express_session); const FileStore = require('session-file-store')(express_session); const host = (process.env.REDIS_HOST || "").trim(); const port = parseInt(process.env.REDIS_PORT || "6379") || 6379; const password = (process.env.REDIS_PASSWORD || ""); const regex_host = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/; let store: any; if (regex_host.test(host)) { const client = redis.createClient({ host: host, port: port, password: password, db: 0, }); store = new RedisStore({ client: client }); } else { store = new FileStore({ path: root_path + "/storage/sessions", // secret: 'rzSAscktkQTV5SmC' }); }; module.exports = express_session({ store: store, secret: "pDzmfpNMXExK9XDK", resave: true, expires: new Date(Date.now() + 60 * 60 * 24 * 30 * 1000), saveUninitialized: true, cookie: { domain: `.${process.env.DOMAIN}`, httpOnly: true, maxAge: 60 * 60 * 24 * 30 * 1000, }, }); })();