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'
44export const loader = ( args : LoaderFunctionArgs ) => {
55 const extra = args . context . extra
66 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 }
89}
910
1011export default function Index ( ) {
11- const { cloudflare, extra } = useLoaderData < typeof loader > ( )
12+ const { cloudflare, extra, myVarInVariables } = useLoaderData < typeof loader > ( )
1213 return (
1314 < div >
1415 < h1 > Remix and Hono</ h1 >
@@ -19,6 +20,7 @@ export default function Index() {
1920 { cloudflare . caches ? 'caches are available' : '' }
2021 </ h3 >
2122 < h4 > Extra is { extra } </ h4 >
23+ < h5 > Var in Variables is { myVarInVariables } </ h5 >
2224 </ div >
2325 )
2426}
Original file line number Diff line number Diff line change 1+ import type { Context } from 'hono'
12import type { PlatformProxy } from 'wrangler'
23
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+ }
511}
612
713type GetLoadContextArgs = {
814 request : Request
915 context : {
10- cloudflare : Omit < PlatformProxy < Env > , 'dispose' | 'caches' | 'cf' > & {
16+ cloudflare : Omit < PlatformProxy < Env [ 'Bindings' ] > , 'dispose' | 'caches' | 'cf' > & {
1117 caches : PlatformProxy < Env > [ 'caches' ] | CacheStorage
1218 cf : Request [ 'cf' ]
1319 }
20+ hono : {
21+ context : Context < Env >
22+ }
1423 }
1524}
1625
@@ -19,6 +28,9 @@ declare module '@remix-run/cloudflare' {
1928 interface AppLoadContext extends ReturnType < typeof getLoadContext > {
2029 // This will merge the result of `getLoadContext` into the `AppLoadContext`
2130 extra : string
31+ hono : {
32+ context : Context < Env >
33+ }
2234 }
2335}
2436
Original file line number Diff line number Diff line change @@ -5,9 +5,13 @@ const app = new Hono<{
55 Bindings : {
66 MY_VAR : string
77 }
8+ Variables : {
9+ MY_VAR_IN_VARIABLES : string
10+ }
811} > ( )
912
1013app . use ( async ( c , next ) => {
14+ c . set ( 'MY_VAR_IN_VARIABLES' , 'My variable set in c.set' )
1115 await next ( )
1216 c . header ( 'X-Powered-By' , 'Remix and Hono' )
1317} )
You can’t perform that action at this time.
0 commit comments