aboutsummaryrefslogtreecommitdiff
path: root/src/config/cacheControlMiddleware.ts
diff options
context:
space:
mode:
authorAbdelaziz Mahdy <[email protected]>2024-12-23 03:27:43 -0400
committerAbdelaziz Mahdy <[email protected]>2024-12-23 03:27:43 -0400
commitdfc278be08b64dc9bb3082059648c5f792a79fcb (patch)
tree7d79ddcf7abf4ad1eea638b9d9544316ca64e6a3 /src/config/cacheControlMiddleware.ts
parentf1f5db84f98818af2c047ea375832e5ded5f021a (diff)
downloadaniwatch-api-dfc278be08b64dc9bb3082059648c5f792a79fcb.tar.xz
aniwatch-api-dfc278be08b64dc9bb3082059648c5f792a79fcb.zip
chore: styling changes to be more consistent
Diffstat (limited to 'src/config/cacheControlMiddleware.ts')
-rw-r--r--src/config/cacheControlMiddleware.ts15
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;