From d2bd078c7e4fd54c2555b40f0597fd037447e3b6 Mon Sep 17 00:00:00 2001 From: ismailmasseran Date: Mon, 6 Jul 2026 13:24:42 +0800 Subject: [PATCH] DONE: fix error where image not showing on digital card, generate letter not working on prod (#5) Co-authored-by: ISMAIL MASSERAN Reviewed-on: https://git.koppkb.com/KoPKB/My-KOPKB/pulls/5 --- .../utils/member-digital-card.utils.ts | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/modules/profile/utils/member-digital-card.utils.ts b/src/modules/profile/utils/member-digital-card.utils.ts index 81f23ed..46e28ff 100644 --- a/src/modules/profile/utils/member-digital-card.utils.ts +++ b/src/modules/profile/utils/member-digital-card.utils.ts @@ -14,14 +14,22 @@ export function buildCardDownloadFileName( export function toProxiedStorageUrl(url: string | null | undefined): string | null | undefined { if (!url) return url - try { - const parsed = new URL(url, window.location.origin) - if (parsed.pathname.startsWith('/storage/')) { - return `${parsed.pathname}${parsed.search}` - } - } catch { - // Keep original URL when parsing fails. - } + const apiBase = import.meta.env.VITE_API_BASE_URL?.replace(/\/$/, '') - return url + try { + const parsed = new URL(url, apiBase || window.location.origin) + if (!parsed.pathname.startsWith('/storage/')) { + return url + } + + // Production serves the SPA from a different host than Laravel storage files. + if (apiBase) { + return `${apiBase}${parsed.pathname}${parsed.search}` + } + + // Dev fallback: Vite proxies /storage to the API. + return `${parsed.pathname}${parsed.search}` + } catch { + return url + } }