@harlan-zw/nuxt-cloudflare 0.0.5 → 0.0.6

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.
package/README.md CHANGED
@@ -13,7 +13,7 @@ The module extracts production patterns already proven in Nuxt SEO and gscdump.
13
13
  - `workers_dev` disabled when a route proves the Worker remains reachable; workers without routes must choose explicitly
14
14
  - Version metadata binding at `CF_VERSION_METADATA`
15
15
  - Workers Caching enabled by default with per-version isolation
16
- - Dynamic responses default to `private, no-store`; rendered HTML is forcibly private and conflicting page route rules fail the build
16
+ - Dynamic responses default to `private, no-store`; rendered HTML is forcibly private and conflicting route rules are diagnosed
17
17
  - Smart Placement enabled by default; explicit region, host, or hostname placement is preserved
18
18
  - Source-map upload when the Nitro build emits maps; explicit `false` is preserved
19
19
  - Module-wide `secrets.required` names copied to each environment; source root secrets remain scoped to the root
@@ -60,7 +60,7 @@ Cloudflare KV requires TTLs of at least 60 seconds.
60
60
 
61
61
  Workers Caching is separate from Nitro's KV-backed cache. It is enabled by default with `cross_version_cache: false`, so each deployment starts with an isolated cache. Dynamic Nitro responses default to `Cache-Control: private, no-store` and `Cloudflare-CDN-Cache-Control: no-store` unless they declare an explicit cache policy. Rendered HTML always receives those private directives; this is required because Cloudflare otherwise heuristically caches a `200` response with no cache header for two hours.
62
62
 
63
- HTML-capable route rules fail the build when they use `cache`, `isr`, `swr`, or publicly cacheable `Cache-Control`, `CDN-Cache-Control`, and `Cloudflare-CDN-Cache-Control` headers. Explicit `private` and `no-store` policies are safe. API and static asset routes remain available for explicit caching. Disable Workers Caching only for a gateway that must execute on every request:
63
+ Potential HTML route rules warn when they use `cache`, `isr`, `swr`, or publicly cacheable `Cache-Control`, `CDN-Cache-Control`, and `Cloudflare-CDN-Cache-Control` headers. Rules proven to be HTML through prerendering, a `.html` path, or an explicit `text/html` content type fail the build. Explicit `private` and `no-store` policies are safe. API, Nuxt OG Image, and static asset routes remain available for explicit caching. Disable Workers Caching only for a gateway that must execute on every request:
64
64
 
65
65
  ```ts
66
66
  export default defineNuxtConfig({
@@ -187,7 +187,7 @@ const doctor = defineCommand({
187
187
  const main = defineCommand({
188
188
  meta: {
189
189
  name: "nuxt-cloudflare",
190
- version: "0.0.5",
190
+ version: "0.0.6",
191
191
  description: "Cloudflare deployment defaults and diagnostics for Nuxt"
192
192
  },
193
193
  subCommands: { doctor }
package/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=4.5.0"
6
6
  },
7
- "version": "0.0.5",
7
+ "version": "0.0.6",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.3",
10
10
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -9,6 +9,7 @@ const NON_HTML_ROUTE_PREFIXES = [
9
9
  "/api",
10
10
  "/_ipx",
11
11
  "/_nuxt",
12
+ "/_og",
12
13
  "/assets",
13
14
  "/fonts",
14
15
  "/images"
@@ -32,17 +33,29 @@ function isHtmlCapableRoute(route) {
32
33
  function isPrivateCachePolicy(value) {
33
34
  return typeof value === "string" && PRIVATE_CACHE_DIRECTIVE_RE.test(value);
34
35
  }
36
+ function hasHtmlContentType(headers) {
37
+ if (!headers)
38
+ return false;
39
+ const contentType = Object.entries(headers).find(([name]) => name.toLowerCase() === "content-type")?.[1];
40
+ return typeof contentType === "string" && /^text\/html(?:;|$)/i.test(contentType);
41
+ }
42
+ function resolveViolationSeverity(route, value) {
43
+ const definitelyHtml = value.prerender === true || /\.html(?:$|[?*])/i.test(route) || hasHtmlContentType(isRecord(value.headers) ? value.headers : void 0);
44
+ return definitelyHtml ? "error" : "warning";
45
+ }
35
46
  function findHtmlCacheRouteRuleViolations(routeRules) {
36
47
  if (!routeRules)
37
48
  return [];
38
49
  return Object.entries(routeRules).flatMap(([route, value]) => {
39
50
  if (!isHtmlCapableRoute(route) || !isRecord(value))
40
51
  return [];
52
+ const severity = resolveViolationSeverity(route, value);
41
53
  const violations = [];
42
54
  for (const name of CACHE_ROUTE_RULE_NAMES) {
43
55
  if (value[name] !== void 0 && value[name] !== false) {
44
56
  violations.push({
45
57
  _tag: "html-cache-route-rule",
58
+ severity,
46
59
  route,
47
60
  configPath: `routeRules.${route}.${name}`
48
61
  });
@@ -54,6 +67,7 @@ function findHtmlCacheRouteRuleViolations(routeRules) {
54
67
  if (CACHE_HEADER_NAMES.has(name.toLowerCase()) && !isPrivateCachePolicy(value.headers[name])) {
55
68
  violations.push({
56
69
  _tag: "html-cache-header",
70
+ severity,
57
71
  route,
58
72
  configPath: `routeRules.${route}.headers.${name}`
59
73
  });
@@ -63,7 +77,10 @@ function findHtmlCacheRouteRuleViolations(routeRules) {
63
77
  });
64
78
  }
65
79
  function formatHtmlCacheRouteRuleViolations(violations) {
66
- return violations.map((violation) => `${violation.configPath}: Workers Caching requires HTML responses to remain private and no-store.`).join("\n");
80
+ return violations.map((violation) => {
81
+ const subject = violation.severity === "error" ? "HTML route" : "Potential HTML route";
82
+ return `${violation.configPath}: ${subject} must remain private and no-store when Workers Cache is enabled.`;
83
+ }).join("\n");
67
84
  }
68
85
 
69
86
  const logger = useLogger("nuxt-cloudflare");
@@ -152,10 +169,14 @@ function setupCloudflareModule(options, nuxt) {
152
169
  if (resolveModuleWorkersCachePolicy(options)._tag === "disabled")
153
170
  return;
154
171
  const violations = findHtmlCacheRouteRuleViolations(nitroConfig.routeRules);
155
- if (violations.length > 0) {
172
+ const warnings = violations.filter((violation) => violation.severity === "warning");
173
+ const errors = violations.filter((violation) => violation.severity === "error");
174
+ if (warnings.length > 0)
175
+ logger.warn(formatHtmlCacheRouteRuleViolations(warnings));
176
+ if (errors.length > 0) {
156
177
  throw new Error(
157
178
  `[nuxt-cloudflare] HTML route rules conflict with Workers Caching:
158
- ${formatHtmlCacheRouteRuleViolations(violations)}`
179
+ ${formatHtmlCacheRouteRuleViolations(errors)}`
159
180
  );
160
181
  }
161
182
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@harlan-zw/nuxt-cloudflare",
3
3
  "type": "module",
4
- "version": "0.0.5",
4
+ "version": "0.0.6",
5
5
  "description": "Opinionated Cloudflare deployment defaults and diagnostics for Nuxt.",
6
6
  "author": {
7
7
  "name": "Harlan Wilton",