2023-02-25 07:39:30 +01:00
|
|
|
|
2023-02-26 15:18:26 +01:00
|
|
|
const express = require('express');
|
|
|
|
const session = require('express-session');
|
|
|
|
const crypto = require('crypto');
|
|
|
|
const router = new express.Router();
|
|
|
|
const parser = require('cookie-parser');
|
|
|
|
|
2023-02-25 07:39:30 +01:00
|
|
|
const Redis = require("ioredis").Redis;
|
|
|
|
/** @type {import('ioredis').Redis} */
|
|
|
|
const redis = new Redis(process.env.REDIS_PORT, process.env.REDIS_HOST);
|
2023-02-26 15:18:26 +01:00
|
|
|
const ConnectRedis = require('connect-redis')(session);
|
|
|
|
const store = new ConnectRedis({client: redis});
|
2023-02-25 07:39:30 +01:00
|
|
|
|
2023-02-26 15:18:26 +01:00
|
|
|
router.use(parser())
|
|
|
|
router.use(session({
|
|
|
|
secret: process.env.APP_KEY,
|
|
|
|
store: store,
|
|
|
|
cookie: {
|
|
|
|
// secure cookies didnt work for some reason
|
|
|
|
secure: false
|
|
|
|
},
|
|
|
|
resave: true,
|
|
|
|
genid: (req) => {
|
|
|
|
return crypto.randomBytes(256).toString('base64');
|
|
|
|
}
|
|
|
|
}));
|
2023-02-25 07:39:30 +01:00
|
|
|
|
|
|
|
module.exports = router;
|