From 059ba0b565e2273b4b78baf3d265c9953de6097b Mon Sep 17 00:00:00 2001 From: mohammad sedighi Date: Wed, 26 Aug 2026 18:01:25 +0330 Subject: [PATCH] fix(files): join storage URLs onto /server so public images load Relative storage paths were resolved on the SPA host instead of the API, so uploaded files 404'd. Co-authored-by: Cursor --- src/utils/productImage.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/utils/productImage.ts b/src/utils/productImage.ts index 1722c30..d0a29c4 100644 --- a/src/utils/productImage.ts +++ b/src/utils/productImage.ts @@ -35,8 +35,17 @@ function storageRelativePath(value: string): string | null { function joinProjectUrl(relative: string): string { const path = relative.replace(/^\//, '') - const base = projectBase() - if (!base) return `/${path}` + let base = projectBase() + if (!base && typeof window !== 'undefined') { + base = `${window.location.origin}/server` + } + if (!base) { + return `/server/${path}` + } + base = base.replace(/\/$/, '') + if (path.startsWith('storage/') && !/\/(server|api)(\/|$)/i.test(base)) { + base = `${base}/server` + } let url = `${base}/${path}` if (typeof window !== 'undefined' && window.location.protocol === 'https:') { url = url.replace(/^http:\/\//i, 'https://') @@ -53,7 +62,7 @@ export function normalizePublicFileUrl(raw?: string | null): string | null { if (/^(data:|blob:)/i.test(trimmed)) return trimmed const storagePath = storageRelativePath(trimmed) - if (storagePath && projectBase()) { + if (storagePath) { return joinProjectUrl(storagePath) }