@cloudhal/astro-renderer 0.3.9 → 0.3.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workers Cache keys by path, not hostname, and answers before the Worker runs (#62). Every host
|
|
3
|
+
* routed to the site Worker — a custom domain, its workers.dev name, a redirect host (#49), the
|
|
4
|
+
* other sites of a multi-site Worker (RFC-0034) — would otherwise share one entry per path. `Vary:
|
|
5
|
+
* Host` makes it keep one variant per host.
|
|
6
|
+
*
|
|
7
|
+
* Worker-safe: no imports.
|
|
8
|
+
*/
|
|
9
|
+
export declare function varyByHost(response: Response): Response;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workers Cache keys by path, not hostname, and answers before the Worker runs (#62). Every host
|
|
3
|
+
* routed to the site Worker — a custom domain, its workers.dev name, a redirect host (#49), the
|
|
4
|
+
* other sites of a multi-site Worker (RFC-0034) — would otherwise share one entry per path. `Vary:
|
|
5
|
+
* Host` makes it keep one variant per host.
|
|
6
|
+
*
|
|
7
|
+
* Worker-safe: no imports.
|
|
8
|
+
*/
|
|
9
|
+
export function varyByHost(response ) {
|
|
10
|
+
const vary = response.headers.get("vary") ?? "";
|
|
11
|
+
if (vary.trim() === "*" || /(^|,)\s*host\s*(,|$)/i.test(vary)) return response;
|
|
12
|
+
// A redirect's or a WebSocket's headers can be immutable; copy them into a fresh response.
|
|
13
|
+
const headers = new Headers(response.headers);
|
|
14
|
+
headers.set("vary", vary.trim() ? `${vary}, Host` : "Host");
|
|
15
|
+
return new Response(response.body, {
|
|
16
|
+
status: response.status,
|
|
17
|
+
statusText: response.statusText,
|
|
18
|
+
headers,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
@@ -54,6 +54,7 @@ import {
|
|
|
54
54
|
SiteAnalytics,
|
|
55
55
|
} from "./analytics.js";
|
|
56
56
|
import { isCloudhalCacheTag } from "./cache-tags.js";
|
|
57
|
+
import { varyByHost } from "./cache-vary.js";
|
|
57
58
|
import { isCommentsPath, SiteComments } from "./comments.js";
|
|
58
59
|
import { SITE_CSP } from "./csp.js";
|
|
59
60
|
import { EMBED_HEADER, withEmbedFrames } from "./embed-client.js";
|
|
@@ -529,21 +530,25 @@ async function serveSite(
|
|
|
529
530
|
|
|
530
531
|
export function createSiteWorker(options = {}) {
|
|
531
532
|
const searchLimiter = new SearchLimiter();
|
|
533
|
+
async function route(request , env , ctx ) {
|
|
534
|
+
const url = new URL(request.url);
|
|
535
|
+
if (url.pathname === "/__cloudhal/purge") return purge(request, env, options.siteId);
|
|
536
|
+
if (url.pathname === "/__cloudhal/features") return features(request, env);
|
|
537
|
+
const moved = hostRedirect(request, env);
|
|
538
|
+
if (moved) return moved;
|
|
539
|
+
// RFC-0034 §4: the hostname picks the site on a multi-site Worker; everything the request
|
|
540
|
+
// runs (Astro's render included) then sees that site.
|
|
541
|
+
const choice = await siteDispatch(env, options.siteId).choose(request);
|
|
542
|
+
if (choice.kind === "unknown") return unknownHost();
|
|
543
|
+
const siteId = choice.siteId;
|
|
544
|
+
const run = () => serveSite({ request, env, ctx }, siteId, searchLimiter);
|
|
545
|
+
const response = siteId ? await withRequestSite(siteId, run) : await run();
|
|
546
|
+
return choice.noindex ? withNoindex(response) : response;
|
|
547
|
+
}
|
|
532
548
|
return {
|
|
533
549
|
async fetch(request , env , ctx ) {
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
if (url.pathname === "/__cloudhal/features") return features(request, env);
|
|
537
|
-
const moved = hostRedirect(request, env);
|
|
538
|
-
if (moved) return moved;
|
|
539
|
-
// RFC-0034 §4: the hostname picks the site on a multi-site Worker; everything the request
|
|
540
|
-
// runs (Astro's render included) then sees that site.
|
|
541
|
-
const choice = await siteDispatch(env, options.siteId).choose(request);
|
|
542
|
-
if (choice.kind === "unknown") return unknownHost();
|
|
543
|
-
const siteId = choice.siteId;
|
|
544
|
-
const run = () => serveSite({ request, env, ctx }, siteId, searchLimiter);
|
|
545
|
-
const response = siteId ? await withRequestSite(siteId, run) : await run();
|
|
546
|
-
return choice.noindex ? withNoindex(response) : response;
|
|
550
|
+
// #62: the edge cache is shared by every host this Worker answers on, unless told to vary.
|
|
551
|
+
return varyByHost(await route(request, env, ctx));
|
|
547
552
|
},
|
|
548
553
|
};
|
|
549
554
|
}
|
|
@@ -27,6 +27,8 @@ export function hostRedirect(request , env )
|
|
|
27
27
|
headers: {
|
|
28
28
|
location: `https://${to}${url.pathname}${url.search}`,
|
|
29
29
|
"cache-control": "public, max-age=86400",
|
|
30
|
+
// Never in the edge cache (#62): it is shared with the hosts this one redirects to.
|
|
31
|
+
"cloudflare-cdn-cache-control": "no-store",
|
|
30
32
|
},
|
|
31
33
|
});
|
|
32
34
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudhal/astro-renderer",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.10",
|
|
4
4
|
"description": "Render a Cloudhal Site Graph with Astro: data sources (live/snapshot), section components and the cloudhal() integration",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://cloudhal.dev",
|
|
@@ -179,14 +179,14 @@
|
|
|
179
179
|
"README.md"
|
|
180
180
|
],
|
|
181
181
|
"dependencies": {
|
|
182
|
-
"@cloudhal/core-contracts": "0.3.
|
|
183
|
-
"@cloudhal/core-ts": "0.3.
|
|
184
|
-
"@cloudhal/storage": "0.3.
|
|
182
|
+
"@cloudhal/core-contracts": "0.3.10",
|
|
183
|
+
"@cloudhal/core-ts": "0.3.10",
|
|
184
|
+
"@cloudhal/storage": "0.3.10",
|
|
185
185
|
"marked": "^18.1.0",
|
|
186
186
|
"parse5": "8.0.1",
|
|
187
|
-
"@cloudhal/analytics": "0.3.
|
|
187
|
+
"@cloudhal/analytics": "0.3.10",
|
|
188
188
|
"vite": "^8.3.3",
|
|
189
|
-
"@cloudhal/comments": "0.3.
|
|
189
|
+
"@cloudhal/comments": "0.3.10"
|
|
190
190
|
},
|
|
191
191
|
"peerDependencies": {
|
|
192
192
|
"astro": "^7.3.0",
|