From 30f0dbef5dd13909933c624f76a05ef650e77159 Mon Sep 17 00:00:00 2001 From: Till-JS <101404291+Till-JS@users.noreply.github.com> Date: Mon, 2 Feb 2026 17:14:03 +0100 Subject: [PATCH] feat(contacts-web): add hooks.server.ts for runtime URL injection Fixes contacts-web using localhost URLs instead of production URLs. SvelteKit bakes environment variables at build time, so we need to inject runtime URLs via hooks.server.ts for Docker deployments. Co-Authored-By: Claude Opus 4.5 --- apps/contacts/apps/web/src/hooks.server.ts | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 apps/contacts/apps/web/src/hooks.server.ts diff --git a/apps/contacts/apps/web/src/hooks.server.ts b/apps/contacts/apps/web/src/hooks.server.ts new file mode 100644 index 000000000..ee537918b --- /dev/null +++ b/apps/contacts/apps/web/src/hooks.server.ts @@ -0,0 +1,31 @@ +/** + * Server Hooks for SvelteKit + * - Injects runtime environment variables for client-side use + * - Auth is handled client-side via Mana Core Auth + */ + +import type { Handle } from '@sveltejs/kit'; + +// Get client-side URLs from environment (Docker runtime) +const PUBLIC_MANA_CORE_AUTH_URL_CLIENT = + process.env.PUBLIC_MANA_CORE_AUTH_URL_CLIENT || process.env.PUBLIC_MANA_CORE_AUTH_URL || ''; +const PUBLIC_BACKEND_URL_CLIENT = + process.env.PUBLIC_BACKEND_URL_CLIENT || process.env.PUBLIC_BACKEND_URL || ''; + +// Cross-app integration URLs +const PUBLIC_TODO_BACKEND_URL = process.env.PUBLIC_TODO_BACKEND_URL || 'http://localhost:3031'; + +export const handle: Handle = async ({ event, resolve }) => { + return resolve(event, { + transformPageChunk: ({ html }) => { + // Inject runtime environment variables into the HTML + // These will be available on window.__PUBLIC_*__ for client-side code + const envScript = ``; + return html.replace('', `${envScript}`); + }, + }); +};