Skip to content

Commit

Permalink
feat(server): redis session cache
Browse files Browse the repository at this point in the history
  • Loading branch information
TyIsI committed Dec 29, 2024
1 parent eecb5ca commit 66d4577
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 19 deletions.
106 changes: 98 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 13 additions & 9 deletions server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,29 @@ const http = require('http')
const https = require('https')
const path = require('path')

const loki = require('connect-loki')
const { RedisStore } = require('connect-redis')
const cors = require('cors')
const debug = require('debug')('tacos:app')
const express = require('express')
const session = require('express-session')
const logger = require('morgan')
const { createClient } = require('redis')

const { config } = require('./lib/config')
const passport = require('./lib/passport')
const middleware = require('./middleware/')

const LokiStore = loki(session)
// Initialize client.
const redisClient = createClient({
url: `redis://default:${process.env.REDIS_PASSWORD}@${process.env.REDIS_HOST}:${process.env.REDIS_PORT}`
})
redisClient.connect()

const lokiStoreOpts = {
path: path.resolve(
path.join(__dirname, '/', config.datadir, '/session-store.db')
),
autosave: true
}
// Initialize store.
const redisStore = new RedisStore({
client: redisClient,
prefix: 'tacos:session:'
})

const app = express()

Expand Down Expand Up @@ -56,7 +60,7 @@ app.use(
// @ts-ignore
session({
secret: config.sessions.secret,
store: new LokiStore(lokiStoreOpts),
store: redisStore,
resave: false,
saveUninitialized: true,
proxy: true,
Expand Down
5 changes: 3 additions & 2 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "Ty Eggen",
"dependencies": {
"@prisma/client": "6.1.0",
"connect-loki": "^1.2.0",
"connect-redis": "^8.0.1",
"cookie-parser": "^1.4.4",
"cors": "^2.8.5",
"crypto-js": "^4.2.0",
Expand All @@ -12,7 +12,7 @@
"eventemitter2": "^6.4.5",
"express": "^4.20.0",
"express-rate-limit": "^7.5.0",
"express-session": "^1.17.2",
"express-session": "^1.18.1",
"lokijs": "^1.5.12",
"morgan": "^1.9.1",
"ms": "^2.1.3",
Expand All @@ -22,6 +22,7 @@
"passport-local": "^1.0.0",
"passport-slack-oauth2": "^1.1.1",
"pug": "^3.0.3",
"redis": "^4.7.0",
"socket.io": "^4.6.2",
"supervisor": "^0.12.0",
"wireit": "^0.14.9"
Expand Down

0 comments on commit 66d4577

Please sign in to comment.