Skip to content

Commit 45fc9e4

Browse files
committed
Align variable name and value with cloudflare-pages
1 parent 3bb3bf5 commit 45fc9e4

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

examples/cloudflare-workers/app/routes/_index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import { useLoaderData } from '@remix-run/react'
44
export const loader = (args: LoaderFunctionArgs) => {
55
const extra = args.context.extra
66
const cloudflare = args.context.cloudflare
7-
const hono_context = args.context.hono.context.get('hono-context')
8-
return { cloudflare, extra, hono_context }
7+
const myVarInVariables = args.context.hono.context.get('MY_VAR_IN_VARIABLES')
8+
return { cloudflare, extra, myVarInVariables }
99
}
1010

1111
export default function Index() {
12-
const { cloudflare, extra, hono_context } = useLoaderData<typeof loader>()
12+
const { cloudflare, extra, myVarInVariables } = useLoaderData<typeof loader>()
1313
return (
1414
<div>
1515
<h1>Remix and Hono</h1>
@@ -20,7 +20,7 @@ export default function Index() {
2020
{cloudflare.caches ? 'caches are available' : ''}
2121
</h3>
2222
<h4>Extra is {extra}</h4>
23-
<h4>hono-context is {hono_context}</h4>
23+
<h5>Var in Variables is {myVarInVariables}</h5>
2424
</div>
2525
)
2626
}

examples/cloudflare-workers/load-context.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
import type { Context } from 'hono'
22
import type { PlatformProxy } from 'wrangler'
33

4-
interface Env {
5-
MY_VAR: string
4+
type Env = {
5+
Bindings: {
6+
MY_VAR: string
7+
}
8+
Variables: {
9+
MY_VAR_IN_VARIABLES: string
10+
}
611
}
712

813
type GetLoadContextArgs = {
914
request: Request
1015
context: {
11-
cloudflare: Omit<PlatformProxy<Env>, 'dispose' | 'caches' | 'cf'> & {
16+
cloudflare: Omit<PlatformProxy<Env['Bindings']>, 'dispose' | 'caches' | 'cf'> & {
1217
caches: PlatformProxy<Env>['caches'] | CacheStorage
1318
cf: Request['cf']
1419
},
1520
hono: {
16-
context: Context
21+
context: Context<Env>
1722
},
1823
}
1924
}
@@ -23,6 +28,9 @@ declare module '@remix-run/cloudflare' {
2328
interface AppLoadContext extends ReturnType<typeof getLoadContext> {
2429
// This will merge the result of `getLoadContext` into the `AppLoadContext`
2530
extra: string
31+
hono: {
32+
context: Context<Env>
33+
}
2634
}
2735
}
2836

examples/cloudflare-workers/server/index.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,21 @@ const app = new Hono<{
66
MY_VAR: string
77
},
88
Variables: {
9-
'hono-context': string
9+
'MY_VAR_IN_VARIABLES': string
1010
},
1111
}>()
1212

1313
app.use(async(c, next) => {
14-
c.set('hono-context', 'hono-context')
14+
c.set('MY_VAR_IN_VARIABLES', 'My variable set in c.set')
1515
await next()
1616
c.header('X-Powered-By', 'Remix and Hono')
1717
})
1818

1919
app.get('/api', (c) => {
2020
return c.json({
2121
message: 'Hello',
22-
var: c.env.MY_VAR
22+
var: c.env.MY_VAR,
2323
})
2424
})
2525

26-
2726
export default app

0 commit comments

Comments
 (0)