Β© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Cloudflare DevelopersCD
Cloudflare Developersβ€’3y agoβ€’
2 replies
xzilja

Is it possible to access env variables outside "fetch handler"

Hey everyone. I'm trying to set up few libraries that rely on on environment secrets, but it seems as if these secrets are only available on
env
env
object inside fetch handler?

I am using https://hono.dev as a routing library and believe the only way to set up something like supabase client at the moment is via middleware

app.use('*', async (ctx, next) => {
  const supabase = createClient(ctx.env.SUPABASE_URL, ctx.env.SUPABASE_SERVICE_ROLE_KEY, {
    auth: { autoRefreshToken: false, persistSession: false }
  })
  ctx.set('supabase', supabase)
  await next()
})
app.use('*', async (ctx, next) => {
  const supabase = createClient(ctx.env.SUPABASE_URL, ctx.env.SUPABASE_SERVICE_ROLE_KEY, {
    auth: { autoRefreshToken: false, persistSession: false }
  })
  ctx.set('supabase', supabase)
  await next()
})


Is it correct to assume that this is the only way or am I missing something obvious here that allows me to get env variables in global scope as well? Thank you
Cloudflare Developers banner
Cloudflare DevelopersJoin
Welcome to the official Cloudflare Developers server. Here you can ask for help and stay updated with the latest news
85,042Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Is it possible to share env variables among workers?
Cloudflare DevelopersCDCloudflare Developers / workers-and-pages-help
3y ago
Binding outside of the fetch handler?
Cloudflare DevelopersCDCloudflare Developers / workers-and-pages-help
17mo ago
No fetch handler!
Cloudflare DevelopersCDCloudflare Developers / workers-and-pages-help
8mo ago
Is it safe to put my env variables during build time?
Cloudflare DevelopersCDCloudflare Developers / workers-and-pages-help
5mo ago