2018-04-17 07:01:06 -05:00
|
|
|
import { Redis } from '../lib/redis'
|
2019-04-25 04:27:13 -05:00
|
|
|
import * as apicache from 'apicache'
|
2020-12-08 14:16:10 -06:00
|
|
|
import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes'
|
2018-04-17 07:01:06 -05:00
|
|
|
|
2019-04-25 04:27:13 -05:00
|
|
|
// Ensure Redis is initialized
|
|
|
|
Redis.Instance.init()
|
2018-05-23 03:03:26 -05:00
|
|
|
|
2020-01-09 09:51:51 -06:00
|
|
|
const defaultOptions = {
|
2019-04-25 04:27:13 -05:00
|
|
|
redisClient: Redis.Instance.getClient(),
|
2020-01-09 09:51:51 -06:00
|
|
|
appendKey: () => Redis.Instance.getPrefix(),
|
|
|
|
statusCodes: {
|
2020-12-08 14:16:10 -06:00
|
|
|
exclude: [
|
|
|
|
HttpStatusCode.FORBIDDEN_403,
|
|
|
|
HttpStatusCode.NOT_FOUND_404
|
|
|
|
]
|
2020-01-09 09:51:51 -06:00
|
|
|
}
|
2018-04-17 07:01:06 -05:00
|
|
|
}
|
|
|
|
|
2020-01-09 09:51:51 -06:00
|
|
|
const cacheRoute = (extraOptions = {}) => apicache.options({
|
|
|
|
...defaultOptions,
|
|
|
|
...extraOptions
|
|
|
|
}).middleware
|
2019-04-25 04:27:13 -05:00
|
|
|
|
2018-04-17 07:01:06 -05:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
2018-07-24 07:35:11 -05:00
|
|
|
cacheRoute
|
2018-04-17 07:01:06 -05:00
|
|
|
}
|