-
Hello, I'm seeing that for get the environment variables as bindings, you use the context from the app[method], but I would like some like dotenv, where you can get the variable calling directly to the environment. I have this, a middleware that get the context and on every request, get the variables from the wrangler.toml and is saved in a static class, so I can get the variables:
So in the code where I want to use the variable:
Question is, can I execute the code inside the middleware as function to execute once on the startup of the worker? because being executed only once to set the variables would be enough. Thank you |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hi @sntmt ! You can't do it, and you don't have to do it if you want the application to run on Cloudflare Workers. On Cloudflare Workers, a Worker is launched for each request. It is not guaranteed that a Worker is always running. So, even if it has a value as static, it may disappear, so it must be retrieved from Bindings each time. |
Beta Was this translation helpful? Give feedback.
-
Hi. I just implement this library today and I found that it's hard to get the right documentation to read the |
Beta Was this translation helpful? Give feedback.
Hi @sntmt !
You can't do it, and you don't have to do it if you want the application to run on Cloudflare Workers. On Cloudflare Workers, a Worker is launched for each request. It is not guaranteed that a Worker is always running. So, even if it has a value as static, it may disappear, so it must be retrieved from Bindings each time.