homepage.js/middleware/session.js

28 lines
789 B
JavaScript
Raw Normal View History

2023-02-25 07:39:30 +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);
const ConnectRedis = require('connect-redis')(session);
const store = new ConnectRedis({client: redis});
2023-02-25 07:39:30 +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;