Rename X-Device to X-OmnivoreClient in the request headers

This commit is contained in:
Hongbo Wu 2022-10-12 10:27:39 +08:00
parent d74eee131c
commit ab86450864
2 changed files with 12 additions and 6 deletions

View file

@ -43,7 +43,13 @@ jobs:
ports:
- 9200
redis:
image: "redis:6.2.7"
image: redis
# Set health checks to wait until redis has started
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6379
steps:

View file

@ -107,16 +107,16 @@ export const createApp = (): {
// set user device from request header to Redis
app.use('/api/', async (req, res, next) => {
const device = req.header('X-Device')
const client = req.header('X-OmnivoreClient')
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 (client && token) {
const key = `client:${token}`
if (!(await redisClient.exists(key))) {
await redisClient.set(key, device, {
EX: 600, // 10 minutes
await redisClient.set(key, client, {
EX: 600, // expires in 10 minutes
NX: true,
})
}