From 19a403b431f1fd34b680bcb9baaa5d5600b1378d Mon Sep 17 00:00:00 2001 From: Leon Serfaty <80597822+silkoserfo@users.noreply.github.com> Date: Sat, 20 Jun 2026 21:10:52 -0400 Subject: [PATCH] fix(storage): serve assets via app routes when MEDIA_PUBLIC_BASE_URL is unset publicUrl() defaulted MEDIA_BASE to "/media" even with no env set, so cover art on public share pages pointed at a /media path that only the old nginx (Plesk) box served. In the containerized Coolify/Docker deploy nothing serves /media, breaking those images. Return null when MEDIA_PUBLIC_BASE_URL is unset so callers fall back to the app's own /api/public/.../cover route (the deploy README already documents assets as app-served). Backward compatible: behavior is unchanged when the env var is set. Co-Authored-By: Claude Opus 4.8 (1M context) --- lib/storage/local.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/storage/local.ts b/lib/storage/local.ts index 411c098..04cd82d 100644 --- a/lib/storage/local.ts +++ b/lib/storage/local.ts @@ -3,7 +3,11 @@ import path from "node:path"; import type { StorageProvider } from "./types"; const STORAGE_DIR = path.resolve(process.env.STORAGE_DIR ?? "./storage"); -const MEDIA_BASE = process.env.MEDIA_PUBLIC_BASE_URL ?? "/media"; +// Only when an external static server (e.g. nginx on the Plesk box) serves the +// art directory is MEDIA_PUBLIC_BASE_URL set. In the containerized deploy it is +// unset and the app serves assets itself via /api routes — so publicUrl() must +// return null then, letting callers fall back instead of pointing at a dead /media. +const MEDIA_BASE = process.env.MEDIA_PUBLIC_BASE_URL?.trim() || null; // Cover art is the only asset class served publicly by nginx from /media. const PUBLIC_PREFIXES = ["art/"]; @@ -67,7 +71,7 @@ export class LocalStorageProvider implements StorageProvider { } publicUrl(key: string): string | null { - if (PUBLIC_PREFIXES.some((p) => key.startsWith(p))) { + if (MEDIA_BASE && PUBLIC_PREFIXES.some((p) => key.startsWith(p))) { return `${MEDIA_BASE}/${key}`; } return null;