Proper way to store Supabase client in Hono Cloudflare Workers
I'm building a Cloudflare Worker using Hono and Supabase, and I'm trying to understand the best way to handle the Supabase client initialization. Specifically, I want to know whether storing the Supabase client in Hono's context is appropriate, given how contexts are handled in the Cloudflare Workers environment.
Are Hono contexts generated for every request or are they maintained at the machine/worker level? This affects whether I should initialize the Supabase client for each request or keep a single instance.
I know I can store the Supabase client in the context like this:
What I'm unsure about:
- Is this creating a new Supabase client for every request?
- If so, is there a more efficient way to handle this in Cloudflare Workers?
- What's the recommended pattern for sharing database clients in Hono?
0 Replies