nuxt-open-fetch icon indicating copy to clipboard operation
nuxt-open-fetch copied to clipboard

Environment variables don't work

Open TheDutchCoder opened this issue 1 year ago • 3 comments

Environment



Reproduction

https://stackblitz.com/edit/github-pljepz?file=nuxt.config.ts

Describe the bug

Env variables are never read on dev start

Additional context

No matter how/where I declare the variables, or the openfetch options (in the root, or in public config), the env vars are never used.

Logs

No response

TheDutchCoder avatar Sep 10 '24 14:09 TheDutchCoder

The only way to get it to work is to manually reference the env variable in the config, like this:

  openFetch: {
    disableNuxtPlugin: true,
    openAPITS: {
      alphabetize: true,
      exportType: true,
    },
    clients: {
      rvezy: {
        schema: process.env.NUXT_PUBLIC_OPEN_FETCH_FOO_SCHEMA,
        baseURL: process.env.NUXT_PUBLIC_OPEN_FETCH_FOO_BASE_URL,
      },
    },
  },

However, this doesn't work when type checking...

TheDutchCoder avatar Sep 10 '24 14:09 TheDutchCoder

@enkot Any change you could look into the open issues?

Currently the module seems very useful, but it can't be used in production because the config part doesn't properly work (yet). Would be more than happy to assist btw.

TheDutchCoder avatar Sep 23 '24 19:09 TheDutchCoder

After digging more, the issue is that the documentation around config is wrong. The only way to sort of make this work is by defining openFetch at the root of the config, not in runtimeConfig and hardcode the baseULR as: process.env.NUXT_OPEN_FETCH_RENTALS_BASE_URL || 'http://localhost/fallback-url'

TheDutchCoder avatar Sep 26 '24 14:09 TheDutchCoder

Hi @TheDutchCoder,

Added not to the docs - https://github.com/enkot/nuxt-open-fetch/commit/4d8d7dedc782e976325871f7aade85b1bb2d21a6

enkot avatar Oct 31 '24 23:10 enkot