]>
Commit | Line | Data |
---|---|---|
1 | import { Redis } from '../lib/redis' | |
2 | import * as apicache from 'apicache' | |
3 | import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes' | |
4 | ||
5 | // Ensure Redis is initialized | |
6 | Redis.Instance.init() | |
7 | ||
8 | const defaultOptions = { | |
9 | redisClient: Redis.Instance.getClient(), | |
10 | appendKey: () => Redis.Instance.getPrefix(), | |
11 | statusCodes: { | |
12 | exclude: [ | |
13 | HttpStatusCode.FORBIDDEN_403, | |
14 | HttpStatusCode.NOT_FOUND_404 | |
15 | ] | |
16 | } | |
17 | } | |
18 | ||
19 | const cacheRoute = (extraOptions = {}) => apicache.options({ | |
20 | ...defaultOptions, | |
21 | ...extraOptions | |
22 | }).middleware | |
23 | ||
24 | // --------------------------------------------------------------------------- | |
25 | ||
26 | export { | |
27 | cacheRoute | |
28 | } |