diff --git a/apps/cards/apps/web/src/hooks.server.ts b/apps/cards/apps/web/src/hooks.server.ts new file mode 100644 index 000000000..c8b0d19df --- /dev/null +++ b/apps/cards/apps/web/src/hooks.server.ts @@ -0,0 +1,32 @@ +import type { Handle } from '@sveltejs/kit'; + +/** + * Inject the runtime client URLs into
on every SSR'd page. + * + * `@mana/shared-auth-ui` reads `window.__PUBLIC_MANA_AUTH_URL__` to know + * where to POST /api/v1/auth/login (and friends). Without this hook the + * client falls back to a relative URL → 404 on cards.mana.how. + * + * `process.env.PUBLIC_MANA_*_URL_CLIENT` come from the container + * environment (docker-compose.macmini.yml). $env/static/public would + * bake the URLs at build time; we want runtime so the same image can + * serve dev and prod. + */ + +const PUBLIC_MANA_AUTH_URL_CLIENT = + process.env.PUBLIC_MANA_AUTH_URL_CLIENT || process.env.PUBLIC_MANA_AUTH_URL || ''; +const PUBLIC_MANA_SYNC_URL_CLIENT = + process.env.PUBLIC_MANA_SYNC_URL_CLIENT || process.env.PUBLIC_MANA_SYNC_URL || ''; + +export const handle: Handle = async ({ event, resolve }) => { + return resolve(event, { + transformPageChunk: ({ html }) => { + const envScript = + ``; + return html.replace('', `${envScript}`); + }, + }); +};