File tree Expand file tree Collapse file tree 3 files changed +23
-5
lines changed
examples/cloudflare-workers Expand file tree Collapse file tree 3 files changed +23
-5
lines changed Original file line number Diff line number Diff line change @@ -4,11 +4,12 @@ import { useLoaderData } from '@remix-run/react'
4
4
export const loader = ( args : LoaderFunctionArgs ) => {
5
5
const extra = args . context . extra
6
6
const cloudflare = args . context . cloudflare
7
- return { cloudflare, extra }
7
+ const myVarInVariables = args . context . hono . context . get ( 'MY_VAR_IN_VARIABLES' )
8
+ return { cloudflare, extra, myVarInVariables }
8
9
}
9
10
10
11
export default function Index ( ) {
11
- const { cloudflare, extra } = useLoaderData < typeof loader > ( )
12
+ const { cloudflare, extra, myVarInVariables } = useLoaderData < typeof loader > ( )
12
13
return (
13
14
< div >
14
15
< h1 > Remix and Hono</ h1 >
@@ -19,6 +20,7 @@ export default function Index() {
19
20
{ cloudflare . caches ? 'caches are available' : '' }
20
21
</ h3 >
21
22
< h4 > Extra is { extra } </ h4 >
23
+ < h5 > Var in Variables is { myVarInVariables } </ h5 >
22
24
</ div >
23
25
)
24
26
}
Original file line number Diff line number Diff line change
1
+ import type { Context } from 'hono'
1
2
import type { PlatformProxy } from 'wrangler'
2
3
3
- interface Env {
4
- MY_VAR : string
4
+ type Env = {
5
+ Bindings : {
6
+ MY_VAR : string
7
+ }
8
+ Variables : {
9
+ MY_VAR_IN_VARIABLES : string
10
+ }
5
11
}
6
12
7
13
type GetLoadContextArgs = {
8
14
request : Request
9
15
context : {
10
- cloudflare : Omit < PlatformProxy < Env > , 'dispose' | 'caches' | 'cf' > & {
16
+ cloudflare : Omit < PlatformProxy < Env [ 'Bindings' ] > , 'dispose' | 'caches' | 'cf' > & {
11
17
caches : PlatformProxy < Env > [ 'caches' ] | CacheStorage
12
18
cf : Request [ 'cf' ]
13
19
}
20
+ hono : {
21
+ context : Context < Env >
22
+ }
14
23
}
15
24
}
16
25
@@ -19,6 +28,9 @@ declare module '@remix-run/cloudflare' {
19
28
interface AppLoadContext extends ReturnType < typeof getLoadContext > {
20
29
// This will merge the result of `getLoadContext` into the `AppLoadContext`
21
30
extra : string
31
+ hono : {
32
+ context : Context < Env >
33
+ }
22
34
}
23
35
}
24
36
Original file line number Diff line number Diff line change @@ -5,9 +5,13 @@ const app = new Hono<{
5
5
Bindings : {
6
6
MY_VAR : string
7
7
}
8
+ Variables : {
9
+ MY_VAR_IN_VARIABLES : string
10
+ }
8
11
} > ( )
9
12
10
13
app . use ( async ( c , next ) => {
14
+ c . set ( 'MY_VAR_IN_VARIABLES' , 'My variable set in c.set' )
11
15
await next ( )
12
16
c . header ( 'X-Powered-By' , 'Remix and Hono' )
13
17
} )
You can’t perform that action at this time.
0 commit comments