Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: pass hono's context in getLoadContext #24

Merged
merged 3 commits into from
Nov 20, 2024

Conversation

yusukebe
Copy link
Owner

@yusukebe yusukebe commented Nov 18, 2024

Fixes #23

@@ -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')
Copy link
Owner Author

Choose a reason for hiding this comment

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

This args.context.hono.context seems verbose, but I don't have a good idea for the naming.

@ogadra
Copy link
Contributor

ogadra commented Nov 20, 2024

@yusukebe
Sorry for the late response.
This is exactly what I was looking for! Thank you!
I think it would be more considerate to update examples/cloudflare-workers .

@yusukebe
Copy link
Owner Author

@ogadra Thank you!

@predaytor What do you think of this? If okay, please review it.

@predaytor
Copy link

@yusukebe would be great! So far I have used the Context Storage middleware to access the Hono context:

import { getContext as getContextStorage } from 'hono/context-storage';

import { type ContextEnv } from './server';

export function getContext() {
	return getContextStorage<ContextEnv>();
}

///

export async function getLoadContext({ context, request }: GetLoadContextArgs) {
	const c = getContext();

	c.var.rateLimit

	return {
		...context,
	};
}

@yusukebe
Copy link
Owner Author

@predaytor

Thanks. I also thought the Context Storage middleware could fit this use case. But the feature in this PR will be helpful!

@yusukebe
Copy link
Owner Author

Seems to be good! I'll merge this now. If you have any requests to change, please feel free to create your PR.

@yusukebe yusukebe merged commit 0b2b917 into main Nov 20, 2024
2 checks passed
@yusukebe yusukebe deleted the feat/hono-context-in-get-load-context branch November 20, 2024 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Question: Why is it not possible to use Context from hono in getLoadContext ?
3 participants