Skip to content

Conversation

@yusukebe
Copy link
Owner

@yusukebe yusukebe commented Nov 18, 2024

Fixes #23

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 ?

4 participants