1
0
Fork 0
peertube/server/middlewares/cache.ts
2021-07-20 15:27:19 +02:00

28 lines
654 B
TypeScript

import * as apicache from 'apicache'
import { HttpStatusCode } from '../../shared/models/http/http-error-codes'
import { Redis } from '../lib/redis'
// Ensure Redis is initialized
Redis.Instance.init()
const defaultOptions = {
redisClient: Redis.Instance.getClient(),
appendKey: () => Redis.Instance.getPrefix(),
statusCodes: {
exclude: [
HttpStatusCode.FORBIDDEN_403,
HttpStatusCode.NOT_FOUND_404
]
}
}
const cacheRoute = (extraOptions = {}) => apicache.options({
...defaultOptions,
...extraOptions
}).middleware
// ---------------------------------------------------------------------------
export {
cacheRoute
}