Datei-Uploads funktionieren wieder mit Adressen ohne Domain

Der lokale Dateianbieter baut die Adresse mit new URL(backend_url) und
scheiterte an "/static" mit "Invalid URL" – jeder Upload brach ab,
auch Produktbilder im Admin.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
torbinus
2026-11-05 12:11:02 +01:00
parent 576ef42c43
commit 288527aa18
4 changed files with 30 additions and 1 deletions
+3 -1
View File
@@ -96,7 +96,9 @@ module.exports = defineConfig({
options: {
providers: [
{
resolve: "@medusajs/file-local",
// Wie @medusajs/file-local, nur mit Adressen ohne Domain —
// siehe src/modules/file-relative.
resolve: "./src/modules/file-relative",
id: "local",
options: {
// Bewusst ohne Domain: Die Adresse landet so in der Datenbank,
+1
View File
@@ -29,6 +29,7 @@
"@medusajs/cli": "2.17.2",
"@medusajs/dashboard": "2.17.2",
"@medusajs/draft-order": "2.17.2",
"@medusajs/file-local": "2.17.2",
"@medusajs/framework": "2.17.2",
"@medusajs/loyalty-plugin": "2.17.2",
"@medusajs/medusa": "2.17.2",
@@ -0,0 +1,25 @@
import { ModuleProvider, Modules } from "@medusajs/framework/utils";
import { LocalFileService } from "@medusajs/file-local";
/**
* Lokale Dateiablage mit Adressen ohne Domain (/static/…).
*
* Der Standardanbieter baut die Adresse mit `new URL(backend_url)` und
* scheitert an einem relativen Pfad mit "Invalid URL" — jeder Upload brach
* ab, auch Produktbilder im Admin. Hier entsteht die Adresse ohne URL-Objekt;
* alles andere bleibt beim Original.
*/
class RelativeLocalFileService extends LocalFileService {
static identifier = "localfs-relative";
constructor(deps: any, options: any) {
super(deps, options);
const basis = String(options?.backend_url ?? "/static").replace(/\/+$/, "");
(this as any).getUploadFileUrl = (fileKey: string) =>
`${basis}/${fileKey.split("/").map(encodeURIComponent).join("/")}`;
}
}
export default ModuleProvider(Modules.FILE, {
services: [RelativeLocalFileService],
});
+1
View File
@@ -32,6 +32,7 @@
"@medusajs/cli": "2.17.2",
"@medusajs/dashboard": "2.17.2",
"@medusajs/draft-order": "2.17.2",
"@medusajs/file-local": "2.17.2",
"@medusajs/framework": "2.17.2",
"@medusajs/loyalty-plugin": "2.17.2",
"@medusajs/medusa": "2.17.2",