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

Env is not available in ctx in Service Worker mode #186

Closed
metrue opened this issue Apr 29, 2022 · 3 comments
Closed

Env is not available in ctx in Service Worker mode #186

metrue opened this issue Apr 29, 2022 · 3 comments

Comments

@metrue
Copy link
Contributor

metrue commented Apr 29, 2022

In Cloudflare Worker, we can set environment variables in wrangler.toml, but I found that it's not accessible when we use Hono in Service Worker mode (app.fire()).

Module Worker mode like following works well.

export default {
  fetch(request, env, event) {
    return app.fetch(request, env, event)
  },
}

I am thinking if we can make environment variables works in app.fire() , it'd be great.

@metrue metrue changed the title It Env is not available in ctx in Service Worker mode Apr 29, 2022
@yusukebe
Copy link
Member

yusukebe commented May 1, 2022

Hi!
I want to have this feature, too. I thought about how to implement it, but I could not find a good way. In Service Worker mode, Environment variables are bound into global variables. In Context, we can bind the variables intoc.env like this:

this.env.API_KEY = globalThis.API_KEY

but we can not know which key to bind. Um-hum. I think using Module Worker mode is better.

@yusukebe
Copy link
Member

yusukebe commented May 1, 2022

Although It's still difficult to bind into c.env. in Service Worker mode, I've implemented a new feature about c.env for Module Worker. See #191 Now, c.env has types.

スクリーンショット 2022-05-01 20 01 48

No, we can handle Env variables more easily.

@yusukebe
Copy link
Member

This issue can be closed.

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

No branches or pull requests

2 participants