cache-control (#423)

Change CACHE_MAX_AGE to CACHE_CONTROL in AWS and Cloudflare
This commit is contained in:
Markus Wendorf
2024-07-09 10:11:33 +02:00
committed by GitHub
parent c2a3fcc5e7
commit dd8fdcd37d
4 changed files with 8 additions and 6 deletions

View File

@@ -1 +1,2 @@
dist dist
node_modules

View File

@@ -232,9 +232,9 @@ export const handlerRaw = async (
data = tilePostprocess(data, header.tileType); data = tilePostprocess(data, header.tileType);
} }
headers["Cache-Control"] = `public, max-age=${ headers["Cache-Control"] =
process.env.CACHE_MAX_AGE || 86400 process.env.CACHE_CONTROL || "public, max-age=86400";
}`;
headers.ETag = `"${createHash("sha256") headers.ETag = `"${createHash("sha256")
.update(Buffer.from(data)) .update(Buffer.from(data))
.digest("hex")}"`; .digest("hex")}"`;

View File

@@ -15,7 +15,7 @@ interface Env {
// biome-ignore lint: config name // biome-ignore lint: config name
BUCKET: R2Bucket; BUCKET: R2Bucket;
// biome-ignore lint: config name // biome-ignore lint: config name
CACHE_MAX_AGE?: number; CACHE_CONTROL?: string;
// biome-ignore lint: config name // biome-ignore lint: config name
PMTILES_PATH?: string; PMTILES_PATH?: string;
// biome-ignore lint: config name // biome-ignore lint: config name
@@ -134,8 +134,9 @@ export default {
) => { ) => {
cacheableHeaders.set( cacheableHeaders.set(
"Cache-Control", "Cache-Control",
`max-age=${env.CACHE_MAX_AGE || 86400}` env.CACHE_CONTROL || "public, max-age=86400"
); );
const cacheable = new Response(body, { const cacheable = new Response(body, {
headers: cacheableHeaders, headers: cacheableHeaders,
status: status, status: status,

View File

@@ -9,4 +9,4 @@ r2_buckets = [
[vars] [vars]
# ALLOWED_ORIGINS = "http://localhost:8000" # ALLOWED_ORIGINS = "http://localhost:8000"
# CACHE_MAX_AGE = 86400 # CACHE_CONTROL = "public, max-age=86400"