Skip to content
This repository was archived by the owner on Jan 14, 2026. It is now read-only.

Commit 8781152

Browse files
Update usage of env to be cross-platform
1 parent a9b068a commit 8781152

File tree

6 files changed

+19
-12
lines changed

6 files changed

+19
-12
lines changed

app/lib/sanity/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { createClient } from '@sanity/client'
2-
import { env } from 'cloudflare:workers'
32

43
// This function should only be called server-side where env is available
4+
// The token must be passed from the loader context where env is accessible
55
export const getSanityClient = (token?: string) => {
66
return createClient({
77
projectId: '0s2zavz0',
88
dataset: 'production',
9-
token: token || env.SANITY_TOKEN,
9+
token: token,
1010
useCdn: true,
1111
apiVersion: '2024-05-31'
1212
})

app/routes/built-with._index.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ export const query = `
3939
}
4040
`
4141

42-
export const loader = async () => {
43-
const client = getSanityClient();
42+
export const loader = async ({ context }) => {
43+
// In dev mode, pass token from context; in production it uses cloudflare:workers env
44+
const sanityToken = context?.cloudflare?.env?.SANITY_TOKEN || context?.env?.SANITY_TOKEN;
45+
const client = getSanityClient(sanityToken);
4446
const response = await client.fetch(query)
4547
return json(response);
4648
};

app/routes/built-with.collections.$slug.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ const query = `
4040
}
4141
`
4242

43-
export const loader = async ({ params: { slug } }) => {
44-
const client = getSanityClient();
43+
export const loader = async ({ params: { slug }, context }) => {
44+
// In dev mode, pass token from context; in production it uses cloudflare:workers env
45+
const sanityToken = context?.cloudflare?.env?.SANITY_TOKEN || context?.env?.SANITY_TOKEN;
46+
const client = getSanityClient(sanityToken);
4547
const response = await client.fetch(query, { slug })
4648
return json(response);
4749
};

app/routes/built-with.projects.$slug.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,10 @@ const query = `
262262
}
263263
`
264264

265-
export const loader = async ({ params: { slug } }) => {
266-
const client = getSanityClient();
265+
export const loader = async ({ params: { slug }, context }) => {
266+
// In dev mode, pass token from context; in production it uses cloudflare:workers env
267+
const sanityToken = context?.cloudflare?.env?.SANITY_TOKEN || context?.env?.SANITY_TOKEN;
268+
const client = getSanityClient(sanityToken);
267269
const response = await client.fetch(query, { slug })
268270
if (!response.project) return redirect("/not-found")
269271
return json(response);

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,10 @@
4848
},
4949
"engines": {
5050
"node": ">=20.0.0"
51+
},
52+
"overrides": {
53+
"@remix-run/dev": {
54+
"wrangler": "$wrangler"
55+
}
5156
}
5257
}

vite.config.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ export default defineConfig({
1818
tsconfigPaths(),
1919
],
2020
ssr: {
21-
external: ["cloudflare:workers"],
2221
resolve: {
2322
conditions: ["workerd", "worker", "browser"],
2423
},
@@ -28,8 +27,5 @@ export default defineConfig({
2827
},
2928
build: {
3029
minify: true,
31-
rollupOptions: {
32-
external: ["cloudflare:workers"],
33-
},
3430
},
3531
});

0 commit comments

Comments
 (0)