Skip to content

feat: allow to edit image config at runtime #1118

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

Open
oemer-aran opened this issue Nov 20, 2023 · 1 comment · May be fixed by #1738
Open

feat: allow to edit image config at runtime #1118

oemer-aran opened this issue Nov 20, 2023 · 1 comment · May be fixed by #1738

Comments

@oemer-aran
Copy link

oemer-aran commented Nov 20, 2023

Unfortunately Nuxt 3 doesn't allow to change env variables used in the nuxt.config.ts at runtime. They are build-time only.
In our pipeline we first build nuxt and then add the environment variables. However, the nuxt.config.ts will still have the undefined values. That's why we need to be able to edit the config at runtime.

The following nuxt config works fine in development but BACKEND_IMAGES_ENDPOINT is undefined in production deployment:

export default defineNuxtConfig({
    // also doesn't work with NUXT_ or NUXT_PUBLIC_ prefix
    domains: [process.env.BACKEND_IMAGES_ENDPOINT],
    alias: {
      "/images": `${process.env.BACKEND_IMAGES_ENDPOINT}/images`
    },
  },
})

I am using the IPX provider and could create a yarn patch to fix this issue for my specific case:

diff --git a/dist/runtime/ipx.mjs b/dist/runtime/ipx.mjs
index dcc2d58828a92d01722267ec8e744799cbc14aad..eb928b04b0687d9a0a5430c02546a3915e908a31 100644
--- a/dist/runtime/ipx.mjs
+++ b/dist/runtime/ipx.mjs
@@ -4,7 +4,18 @@ import { lazyEventHandler, useBase } from "h3";
 import { isAbsolute } from "pathe";
 import { useRuntimeConfig } from "#imports";
 export default lazyEventHandler(() => {
-  const opts = useRuntimeConfig().ipx || {};
+  const config = useRuntimeConfig()
+
+  let opts = config.ipx || {};
+  opts = {
+    ...opts,
+    http: { domains: [config.public.BACKEND_IMAGES_ENDPOINT] },
+    alias: {
+      "/images": `${config.public.BACKEND_IMAGES_ENDPOINT}/images`,
+    },
+  }
+ 
   const fsDir = opts.fs?.dir ? isAbsolute(opts.fs.dir) ? opts.fs.dir : fileURLToPath(new URL(opts.fs.dir, import.meta.url)) : void 0;
   const fsStorage = opts.fs?.dir ? ipxFSStorage({ ...opts.fs, dir: fsDir }) : void 0;
   const httpStorage = opts.http?.domains ? ipxHttpStorage({ ...opts.http }) : void 0;

This is obviously bad, but hopefully helps you understand my issue better.

@oemer-aran oemer-aran changed the title feat: allow to edit image config during runtime feat: allow to edit image config at runtime Nov 20, 2023
@alexan
Copy link

alexan commented Feb 7, 2025

is there any new regarding this?

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

Successfully merging a pull request may close this issue.

2 participants