Merge pull request #85 from kitpdr/fix/convex-env-guards
fix(deploy): guard missing Convex URL
2 files · +10 -2
M src/lib/db/convex.server.ts +5 -1
| @@ -3,7 +3,11 @@ import { env as publicEnv } from '$env/dynamic/public'; | |||
| 3 | 3 | ||
| 4 | 4 | // Convert .cloud URL to .site URL for HTTP actions | |
| 5 | 5 | function getHttpUrl(): string { | |
| 6 | - | return publicEnv.PUBLIC_CONVEX_URL.replace('.convex.cloud', '.convex.site'); | |
| 6 | + | const baseUrl = publicEnv.PUBLIC_CONVEX_URL ?? privateEnv.PUBLIC_CONVEX_URL; | |
| 7 | + | if (!baseUrl) { | |
| 8 | + | throw new Error('PUBLIC_CONVEX_URL is not set'); | |
| 9 | + | } | |
| 10 | + | return baseUrl.replace('.convex.cloud', '.convex.site'); | |
| 7 | 11 | } | |
| 8 | 12 | ||
| 9 | 13 | // Generic fetch helper for Convex HTTP endpoints (server-side only) | |
| @@ -3,7 +3,11 @@ import { env as publicEnv } from '$env/dynamic/public'; | |||||
| 3 | 3 | ||||
| 4 | // Convert .cloud URL to .site URL for HTTP actions | 4 | // Convert .cloud URL to .site URL for HTTP actions | ||
| 5 | function getHttpUrl(): string { | 5 | function getHttpUrl(): string { | ||
| 6 | - | return publicEnv.PUBLIC_CONVEX_URL.replace('.convex.cloud', '.convex.site'); | 6 | + | const baseUrl = publicEnv.PUBLIC_CONVEX_URL ?? privateEnv.PUBLIC_CONVEX_URL; |
| 7 | + | if (!baseUrl) { | |||
| 8 | + | throw new Error('PUBLIC_CONVEX_URL is not set'); | |||
| 9 | + | } | |||
| 10 | + | return baseUrl.replace('.convex.cloud', '.convex.site'); | |||
| 7 | } | 11 | } | ||
| 8 | 12 | ||||
| 9 | // Generic fetch helper for Convex HTTP endpoints (server-side only) | 13 | // Generic fetch helper for Convex HTTP endpoints (server-side only) | ||
M src/routes/+layout.svelte +5 -1
| @@ -7,7 +7,11 @@ | |||
| 7 | 7 | import { browser } from '$app/environment'; | |
| 8 | 8 | ||
| 9 | 9 | // Initialize Convex client for real-time subscriptions | |
| 10 | - | setupConvex(env.PUBLIC_CONVEX_URL); | |
| 10 | + | if (browser && env.PUBLIC_CONVEX_URL) { | |
| 11 | + | setupConvex(env.PUBLIC_CONVEX_URL); | |
| 12 | + | } else if (browser && !env.PUBLIC_CONVEX_URL) { | |
| 13 | + | console.error('Missing PUBLIC_CONVEX_URL for Convex client setup'); | |
| 14 | + | } | |
| 11 | 15 | ||
| 12 | 16 | let { children, data } = $props(); | |
| 13 | 17 | let isVisible = $state(true); | |
| @@ -7,7 +7,11 @@ | |||||
| 7 | import { browser } from '$app/environment'; | 7 | import { browser } from '$app/environment'; | ||
| 8 | 8 | ||||
| 9 | // Initialize Convex client for real-time subscriptions | 9 | // Initialize Convex client for real-time subscriptions | ||
| 10 | - | setupConvex(env.PUBLIC_CONVEX_URL); | 10 | + | if (browser && env.PUBLIC_CONVEX_URL) { |
| 11 | + | setupConvex(env.PUBLIC_CONVEX_URL); | |||
| 12 | + | } else if (browser && !env.PUBLIC_CONVEX_URL) { | |||
| 13 | + | console.error('Missing PUBLIC_CONVEX_URL for Convex client setup'); | |||
| 14 | + | } | |||
| 11 | 15 | ||||
| 12 | let { children, data } = $props(); | 16 | let { children, data } = $props(); | ||
| 13 | let isVisible = $state(true); | 17 | let isVisible = $state(true); | ||