Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 myVarInVariables = args.context.hono.context.get('MY_VAR_IN_VARIABLES')
return { cloudflare, extra, myVarInVariables }
}

export default function Index() {
const { cloudflare, extra } = useLoaderData<typeof loader>()
const { cloudflare, extra, myVarInVariables } = 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>
<h5>Var in Variables is {myVarInVariables}</h5>
</div>
)
}
18 changes: 15 additions & 3 deletions examples/cloudflare-workers/load-context.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
import type { Context } from 'hono'
import type { PlatformProxy } from 'wrangler'

interface Env {
MY_VAR: string
type Env = {
Bindings: {
MY_VAR: string
}
Variables: {
MY_VAR_IN_VARIABLES: string
}
}

type GetLoadContextArgs = {
request: Request
context: {
cloudflare: Omit<PlatformProxy<Env>, 'dispose' | 'caches' | 'cf'> & {
cloudflare: Omit<PlatformProxy<Env['Bindings']>, 'dispose' | 'caches' | 'cf'> & {
caches: PlatformProxy<Env>['caches'] | CacheStorage
cf: Request['cf']
}
hono: {
context: Context<Env>
}
}
}

Expand All @@ -19,6 +28,9 @@ declare module '@remix-run/cloudflare' {
interface AppLoadContext extends ReturnType<typeof getLoadContext> {
// This will merge the result of `getLoadContext` into the `AppLoadContext`
extra: string
hono: {
context: Context<Env>
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions examples/cloudflare-workers/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ const app = new Hono<{
Bindings: {
MY_VAR: string
}
Variables: {
MY_VAR_IN_VARIABLES: string
}
}>()

app.use(async (c, next) => {
c.set('MY_VAR_IN_VARIABLES', 'My variable set in c.set')
await next()
c.header('X-Powered-By', 'Remix and Hono')
})
Expand Down