Skip to content

Commit 15037cd

Browse files
committed
refactor(image): pick provider from NUXT_IMAGE_PROVIDER build variable
Replace the implicit `WORKERS_CI_BRANCH === 'release'` branch-name check with an explicit `NUXT_IMAGE_PROVIDER` build variable, set per Wrangler environment in Cloudflare Workers Builds. The `production` environment sets it to `cloudflare`; preview and local builds leave it unset and fall back to `none`. Also drop the stale `NUXT_IMAGE_PROVIDER` entry from the Worker `vars` — it was a runtime var that nothing read, and keeping it next to the new build variable of the same name was just confusing. https://claude.ai/code/session_01TWED5ZjQD6uv434RqTBaY2
1 parent 57ba75e commit 15037cd

1 file changed

Lines changed: 17 additions & 13 deletions

File tree

nuxt.config.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ import {defineOrganization} from 'nuxt-schema-org/schema'
33
import tailwindcss from "@tailwindcss/vite";
44
import pkg from './package.json' assert {type: 'json'}
55

6-
// Cloudflare Workers Builds deploys the `release` branch as production and
7-
// every other branch (incl. `main`) as a preview. The Cloudflare image proxy
8-
// (img.onelitefeather.net) only serves the live site, so preview deploys must
9-
// not route images through it — otherwise every branch-new asset 404s.
10-
const isProductionImageHost = process.env.WORKERS_CI_BRANCH === 'release'
6+
// Image provider is chosen at build time from the NUXT_IMAGE_PROVIDER build
7+
// variable, set per Wrangler environment in Cloudflare Workers Builds. The
8+
// `production` environment sets it to `cloudflare` to route images through
9+
// the img.onelitefeather.net proxy; preview/local builds leave it unset and
10+
// fall back to `none`, serving the originals straight from the deploy's own
11+
// /public — the proxy only knows the live site and would 404 branch assets.
12+
const imageProvider = process.env.NUXT_IMAGE_PROVIDER === 'cloudflare'
13+
? 'cloudflare'
14+
: 'none'
1115

1216
export default defineNuxtConfig({
1317
compatibilityDate: '2025-05-15',
@@ -131,10 +135,10 @@ export default defineNuxtConfig({
131135
version: pkg.version
132136
},
133137
image: {
134-
// Production routes images through the Cloudflare image proxy; preview
135-
// and local builds use the `none` provider so originals are served
136-
// straight from the deployment's own /public, which always exists.
137-
provider: isProductionImageHost ? 'cloudflare' : 'none',
138+
// Provider is resolved from the NUXT_IMAGE_PROVIDER build variable
139+
// (see the note at the top of this file). `cloudflare` on production,
140+
// `none` everywhere else.
141+
provider: imageProvider,
138142
// Prefer modern formats with automatic fallback for browsers that don't support them.
139143
format: ['avif', 'webp'],
140144
// Slightly lower default quality to trim payloads without obvious visual loss.
@@ -305,10 +309,10 @@ export default defineNuxtConfig({
305309
database_name: 'launchpad',
306310
database_id: 'a92127c1-aaa3-4753-82ba-ea59fa9e7140'
307311
}
308-
],
309-
vars: {
310-
"NUXT_IMAGE_PROVIDER": "cloudflare",
311-
}
312+
]
313+
// NUXT_IMAGE_PROVIDER is a Cloudflare Workers Builds build
314+
// variable (read at build time in nuxt.config, see top of
315+
// file) — not a runtime Worker var, so it is not in `vars`.
312316
}
313317
}
314318
}

0 commit comments

Comments
 (0)