mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Device info expires in 10 mins
This commit is contained in:
parent
2210a38982
commit
2ba9247a98
1 changed files with 19 additions and 12 deletions
|
|
@ -105,6 +105,25 @@ export const createApp = (): {
|
|||
app.use('/api/', apiLimiter)
|
||||
}
|
||||
|
||||
// set user device from request header to Redis
|
||||
app.use('/api/', async (req, res, next) => {
|
||||
const device = req.header('X-Device')
|
||||
const token =
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
req.header('Authorization') || (req.cookies['auth'] as string | undefined)
|
||||
|
||||
if (device && token) {
|
||||
const key = `device:${token}`
|
||||
if (!(await redisClient.exists(key))) {
|
||||
await redisClient.set(key, device, {
|
||||
EX: 600, // 10 minutes
|
||||
NX: true,
|
||||
})
|
||||
}
|
||||
}
|
||||
next()
|
||||
})
|
||||
|
||||
// respond healthy to auto-scaler.
|
||||
app.get('/_ah/health', (req, res) => res.sendStatus(200))
|
||||
|
||||
|
|
@ -134,18 +153,6 @@ export const createApp = (): {
|
|||
// The error handler must be before any other error middleware and after all routes
|
||||
app.use(Sentry.Handlers.errorHandler())
|
||||
|
||||
// set user device from request header to Redis
|
||||
app.use('/api/', async (req, res, next) => {
|
||||
const device = req.header('X-Device')
|
||||
const token =
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
req.header('Authorization') || (req.cookies['auth'] as string | undefined)
|
||||
if (device && token) {
|
||||
await redisClient.set(`device:${token}`, device)
|
||||
}
|
||||
next()
|
||||
})
|
||||
|
||||
const apollo = makeApolloServer()
|
||||
const httpServer = createServer(app)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue