nitrojs / nitro

Next Generation Server Toolkit. Create web servers with everything you need and deploy them wherever you prefer.
https://nitro.build
MIT License
6.29k stars 520 forks source link

Cloudflare: Environment variables starting with `NITRO_` are not passed to runtimeConfig #2468

Open MickL opened 6 months ago

MickL commented 6 months ago

Environment

nitropack: 2.9.6

Reproduction

-

Describe the bug

Environment variables dont seem to work on Cloudflare:

export default defineNitroConfig({
  runtimeConfig: {
    myVar: ''
  },
});

This works locally with .env:

NITRO_MY_VAR="Hello world"

But deployed to Cloudflare with the environment set in Cloudflare Dashboard it stays empty. Using the following workaround it works:

  runtimeConfig: {
    myVar: process.env.NITRO_MY_VAR,
  },

But what would then the purpose of defining NITRO_ env vars in the first place when they are not auto "injected"?

Additional context

No response

Logs

No response

pi0 commented 6 months ago

Do you call runtimeConfig(event) inside an event handler? Due to how late cloudflare provides environment (during request) it is a limitation.

MickL commented 6 months ago

I do not. It works with the example above so in nuxt/nitro config the process env is there?

te1 commented 5 months ago

See also https://github.com/Atinux/nuxt-env-repro which gives this output (called from inside an event handler):

{
  "runtimeConfig().hello": "",
  "runtimeConfig(event).hello": "world",
  "process.env.NUXT_HELLO": "world"
}
jamaluddinrumi commented 1 week ago

might be you want to ensure NITRO_ env vars are passed to runtimeConfig by reassign them on request hook.

i'm facing only my env vars are passed to runtimeConfig.

and i reassign them to ensure they are all passed and voila, they are there all inside runtimeConfig.

reference https://github.com/nitrojs/nitro/pull/2575#issuecomment-2480455926