Skip to content

Conversation

@kaffolder7
Copy link
Collaborator

Hey @rajnandan1, what about this approach for keeping KENER_BASE_PATH dynamic on runtime? Will need you to pull this fork and help with some testing as there are many changes I made in this one. Essentially, here is the approach I tried taking...

I defined BASE_PATH in constants.js and passed it through load() in .server.js files. This ensures that:

  • KENER_BASE_PATH is evaluated only on the server, preventing it from being baked into the client-side build.
  • The value is passed dynamically to the client via load(), avoiding direct exposure of environment variables.
  • Extra API requests are avoided since the value is retrieved during SSR and injected into the page context.

Process:

  1. Sanitizes KENER_BASE_PATH environment variable server-side.
  2. Defines & exports BASE_PATH variable (to be used by other server-side components).
  3. Imports BASE_PATH from constants.js across various .server.js files
  4. Exports basePath variable via load() functions
  5. basePath variable is passed via data prop to .svelte template files

* Sanitizes `KENER_BASE_PATH` environment variable server-side.
* Defines & exports `BASE_PATH` variable (server-side).
* Imports `BASE_PATH` from server `constants.js` across various `.server.js` files.
* Exports `basePath` variable via `load()` functions.
* Passes `basePath` variable via `data` prop.
@kaffolder7
Copy link
Collaborator Author

Raj, this doesn't seem to be working either after building the Docker image. Would be nice to have another set of eyes on this as it's getting a bit outside my familiarity/comfortability with Svelte. Thought the approach I took would work, but maybe instead Sveltekit's $env/dynamic/private and $env/dynamic/public would be a better approach where KENER_BASE_PATH could be used server-side and PUBLIC_KENER_BASE_PATH can be referenced client-side to pull in the environment variable dynamically.

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 this pull request may close these issues.

1 participant