Backend-Adresse zur Laufzeit statt fest im Image
Astro setzt PUBLIC_-Variablen beim Bauen ein, deshalb gehörte bisher jedes Frontend-Image zu genau einer Umgebung: Heimnetz, Testsystem und Produktion brauchten je einen eigenen Build. Jetzt liest der Server die Adresse beim Start aus der Umgebung und gibt sie als <meta> an den Browser weiter. MEDUSA_INTERNAL_URL erlaubt dem Frontend-Container zusätzlich den direkten Weg zum Backend, ohne Umweg über den Reverse Proxy. Ein Image passt damit überall, ein Adresswechsel ist eine Variable. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -58,8 +58,8 @@ import Layout from "../../layouts/Layout.astro";
|
||||
// The invoice route needs the publishable API key header, which a
|
||||
// plain link click can't send — fetch it ourselves and open the
|
||||
// resulting PDF as a blob instead.
|
||||
const backendUrl = import.meta.env.PUBLIC_MEDUSA_BACKEND_URL;
|
||||
const key = import.meta.env.PUBLIC_MEDUSA_PUBLISHABLE_KEY;
|
||||
const backendUrl = document.querySelector('meta[name="medusa-backend-url"]').content;
|
||||
const key = document.querySelector('meta[name="medusa-publishable-key"]').content;
|
||||
const res = await fetch(`${backendUrl}/store/orders/${order.id}/invoice`, {
|
||||
headers: { "x-publishable-api-key": key },
|
||||
});
|
||||
|
||||
@@ -185,8 +185,8 @@ const allLabels = order.fulfillments.flatMap((f) => f.labels);
|
||||
const displayId = invoiceButton.dataset.displayId;
|
||||
invoiceButton.disabled = true;
|
||||
try {
|
||||
const backendUrl = import.meta.env.PUBLIC_MEDUSA_BACKEND_URL;
|
||||
const key = import.meta.env.PUBLIC_MEDUSA_PUBLISHABLE_KEY;
|
||||
const backendUrl = document.querySelector('meta[name="medusa-backend-url"]').content;
|
||||
const key = document.querySelector('meta[name="medusa-publishable-key"]').content;
|
||||
const res = await fetch(`${backendUrl}/store/orders/${orderId}/invoice`, {
|
||||
headers: { "x-publishable-api-key": key },
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user