Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions examples/cloudflare-workers/app/routes/_index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import { useLoaderData } from '@remix-run/react'
export const loader = (args: LoaderFunctionArgs) => {
const extra = args.context.extra
const cloudflare = args.context.cloudflare
return { cloudflare, extra }
const hono_context = args.context.hono.context.get('hono-context')
return { cloudflare, extra, hono_context }
}

export default function Index() {
const { cloudflare, extra } = useLoaderData<typeof loader>()
const { cloudflare, extra, hono_context } = useLoaderData<typeof loader>()
return (
<div>
<h1>Remix and Hono</h1>
Expand All @@ -19,6 +20,7 @@ export default function Index() {
{cloudflare.caches ? 'caches are available' : ''}
</h3>
<h4>Extra is {extra}</h4>
<h4>hono-context is {hono_context}</h4>
</div>
)
}
6 changes: 5 additions & 1 deletion examples/cloudflare-workers/load-context.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Context } from 'hono'
import type { PlatformProxy } from 'wrangler'

interface Env {
Expand All @@ -10,7 +11,10 @@ type GetLoadContextArgs = {
cloudflare: Omit<PlatformProxy<Env>, 'dispose' | 'caches' | 'cf'> & {
caches: PlatformProxy<Env>['caches'] | CacheStorage
cf: Request['cf']
}
},
hono: {
context: Context
},
}
}

Expand Down
6 changes: 5 additions & 1 deletion examples/cloudflare-workers/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ import { Hono } from 'hono'
const app = new Hono<{
Bindings: {
MY_VAR: string
}
},
Variables: {
'hono-context': string
},
}>()

app.use(async(c, next) => {
c.set('hono-context', 'hono-context')
Copy link
Contributor Author

@ogadra ogadra Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to change the variable's name and value.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

await next()
c.header('X-Powered-By', 'Remix and Hono')
})
Expand Down