Skip to content

web search done right

use static env variables in frontend https://kit.svelte.dev/docs/migrating-to-sveltekit-2#dynamic-environment-variables-cannot-be-used-during-prerendering

Mikkel Denker9e1bb23a9613
diff --git a/frontend/.env b/frontend/.env
new file mode 100644
index 00000000..efbb9bbc
--- /dev/null
+++ b/frontend/.env
@@ -0,0 +1 @@
+PUBLIC_API_BASE=http://localhost:3000
diff --git a/frontend/src/routes/+layout.ts b/frontend/src/routes/+layout.ts
index 911a3f6e..260f28e5 100644
--- a/frontend/src/routes/+layout.ts
+++ b/frontend/src/routes/+layout.ts
@@ -1,8 +1,8 @@
-import { env } from '$env/dynamic/public';
+import { PUBLIC_API_BASE } from '$env/static/public';
import { setGlobalApiBase } from '$lib/api';
import { globals } from '$lib/globals';
import type { LayoutLoad } from './$types';
-setGlobalApiBase(env.PUBLIC_API_BASE || 'http://0.0.0.0:3000');
+setGlobalApiBase(PUBLIC_API_BASE || 'http://0.0.0.0:3000');
export const load: LayoutLoad = async () => ({ globals: await globals() });