1
0
Fork 0
peertube/server/middlewares/cache.ts

29 lines
659 B
TypeScript
Raw Normal View History

2018-04-17 08:01:06 -04:00
import { Redis } from '../lib/redis'
import * as apicache from 'apicache'
import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes'
2018-04-17 08:01:06 -04:00
// 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
]
}
2018-04-17 08:01:06 -04:00
}
const cacheRoute = (extraOptions = {}) => apicache.options({
...defaultOptions,
...extraOptions
}).middleware
2018-04-17 08:01:06 -04:00
// ---------------------------------------------------------------------------
export {
2018-07-24 08:35:11 -04:00
cacheRoute
2018-04-17 08:01:06 -04:00
}