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 <cursoragent@cursor.com>
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user