From 01c00e1503a291e38f92e4437636676f6b00c494 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20Val=C3=A9rio?= Date: Sat, 1 May 2021 15:54:04 +0100 Subject: [PATCH] make cache max-age setting configurable --- index.js | 3 ++- wrangler.toml.example | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 058439b..bd793a0 100644 --- a/index.js +++ b/index.js @@ -19,6 +19,7 @@ async function handleRequest(request) { const cacheUrl = new URL(request.url) const cacheKey = new Request(cacheUrl.toString(), request) const cache = caches.default + const cacheMaxAge = CACHE_MAX_AGE || 3600 let response = await cache.match(cacheKey) if (response) return response @@ -29,7 +30,7 @@ async function handleRequest(request) { response = new Response(content, { headers: { 'content-type': 'text/html;charset=UTF-8', - 'Cache-Control': 'max-age=3600', + 'Cache-Control': `max-age=${cacheMaxAge}`, 'Content-Security-Policy': "script-src 'none'; style-src cdn.jsdelivr.net;", }, diff --git a/wrangler.toml.example b/wrangler.toml.example index bc5e746..5c76cee 100644 --- a/wrangler.toml.example +++ b/wrangler.toml.example @@ -14,6 +14,7 @@ FEEDS = "" MAX_SIZE = 50 TITLE = "ADD_YOUR_TITLE_HERE" DESCRIPTION = "ADD_YOUR_DESCRIPTION_HERE" +CACHE_MAX_AGE = "NUMBER_OF_SECONDS" [triggers] crons = ["0 */2 * * *"]