2018-04-17 08:01:06 -04:00
|
|
|
import { Redis } from '../lib/redis'
|
2019-04-25 05:27:13 -04:00
|
|
|
import * as apicache from 'apicache'
|
2018-04-17 08:01:06 -04:00
|
|
|
|
2019-04-25 05:27:13 -04:00
|
|
|
// Ensure Redis is initialized
|
|
|
|
Redis.Instance.init()
|
2018-05-23 04:03:26 -04:00
|
|
|
|
2020-01-09 10:51:51 -05:00
|
|
|
const defaultOptions = {
|
2019-04-25 05:27:13 -04:00
|
|
|
redisClient: Redis.Instance.getClient(),
|
2020-01-09 10:51:51 -05:00
|
|
|
appendKey: () => Redis.Instance.getPrefix(),
|
|
|
|
statusCodes: {
|
|
|
|
exclude: [ 404, 403 ]
|
|
|
|
}
|
2018-04-17 08:01:06 -04:00
|
|
|
}
|
|
|
|
|
2020-01-09 10:51:51 -05:00
|
|
|
const cacheRoute = (extraOptions = {}) => apicache.options({
|
|
|
|
...defaultOptions,
|
|
|
|
...extraOptions
|
|
|
|
}).middleware
|
2019-04-25 05:27:13 -04:00
|
|
|
|
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
|
|
|
}
|