Skip to content

Commit 257d2fd

Browse files
committed
fix cloudflare adapters
1 parent 26da5ad commit 257d2fd

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

packages/adapter-cloudflare-workers/files/entry.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const static_asset_manifest = JSON.parse(static_asset_manifest_json);
66

77
const server = new Server(manifest);
88

9-
const prefix = `/${manifest.appDir}/immutable/`;
9+
const prefix = `/${manifest.appDir}/`;
1010

1111
export default {
1212
/**
@@ -23,11 +23,15 @@ export default {
2323
const res = await get_asset_from_kv(req, env, context);
2424
if (is_error(res.status)) return res;
2525

26+
const cache_control = url.pathname.startsWith(prefix + 'immutable/')
27+
? 'public, immutable, max-age=31536000'
28+
: 'no-cache';
29+
2630
return new Response(res.body, {
2731
headers: {
28-
// include original cache headers, minus cache-control which
32+
// include original headers, minus cache-control which
2933
// is overridden, and etag which is no longer useful
30-
'cache-control': 'public, immutable, max-age=31536000',
34+
'cache-control': cache_control,
3135
'content-type': res.headers.get('content-type'),
3236
'x-robots-tag': 'noindex'
3337
}

packages/adapter-cloudflare/src/worker.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as Cache from 'worktop/cfw.cache';
44

55
const server = new Server(manifest);
66

7-
const prefix = `/${manifest.appDir}/immutable/`;
7+
const prefix = `/${manifest.appDir}/`;
88

99
/** @type {import('worktop/cfw').Module.Worker<{ ASSETS: import('worktop/cfw.durable').Durable.Object }>} */
1010
const worker = {
@@ -20,11 +20,15 @@ const worker = {
2020
if (pathname.startsWith(prefix)) {
2121
res = await env.ASSETS.fetch(req);
2222

23+
const cache_control = pathname.startsWith(prefix + 'immutable/')
24+
? 'public, immutable, max-age=31536000'
25+
: 'no-cache';
26+
2327
res = new Response(res.body, {
2428
headers: {
25-
// include original cache headers, minus cache-control which
29+
// include original headers, minus cache-control which
2630
// is overridden, and etag which is no longer useful
27-
'cache-control': 'public, immutable, max-age=31536000',
31+
'cache-control': cache_control,
2832
'content-type': res.headers.get('content-type'),
2933
'x-robots-tag': 'noindex'
3034
}

0 commit comments

Comments
 (0)