diff options
Diffstat (limited to 'src/config/cacheControlMiddleware.ts')
| -rw-r--r-- | src/config/cacheControlMiddleware.ts | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/config/cacheControlMiddleware.ts b/src/config/cacheControlMiddleware.ts new file mode 100644 index 0000000..47035ed --- /dev/null +++ b/src/config/cacheControlMiddleware.ts @@ -0,0 +1,15 @@ +import type { MiddlewareHandler } from "hono"; + +// Define middleware to add Cache-Control header +const cacheControlMiddleware: MiddlewareHandler = async (c, next) => { + const sMaxAge = process.env.ANIWATCH_API_S_MAXAGE || "60"; + const staleWhileRevalidate = process.env.ANIWATCH_API_STALE_WHILE_REVALIDATE || "30"; + c.header( + "Cache-Control", + `s-maxage=${sMaxAge}, stale-while-revalidate=${staleWhileRevalidate}` + ); + + await next(); +}; + +export default cacheControlMiddleware; |
