Quellcode durchsuchen

fix(dashboard): Fix port:auto for api requests (#3980)

Tim Siebels vor 1 Monat
Ursprung
Commit
14f42c08e0
1 geänderte Dateien mit 10 neuen und 2 gelöschten Zeilen
  1. 10 2
      packages/dashboard/src/lib/utils/config-utils.ts

+ 10 - 2
packages/dashboard/src/lib/utils/config-utils.ts

@@ -1,11 +1,19 @@
 import { uiConfig } from 'virtual:vendure-ui-config';
 
+/**
+ * Returns the base URL for API requests based on the configuration.
+ * Respects the 'auto' setting to derive the URL from the current location.
+ *
+ * @returns {string} The constructed API base URL, e.g. https://api.example.test:3070
+ */
 export function getApiBaseUrl(): string {
     const schemeAndHost =
         uiConfig.api.host !== 'auto'
             ? uiConfig.api.host
-            : `${window.location.protocol}//${window.location.hostname}`;
-    const portPart = uiConfig.api.port !== 'auto' ? `:${uiConfig.api.port}` : '';
+            : `${globalThis.location.protocol}//${globalThis.location.hostname}`;
+
+    const locationPortPart = globalThis.location.port ? `:${globalThis.location.port}` : '';
+    const portPart = uiConfig.api.port === 'auto' ? locationPortPart : `:${uiConfig.api.port}`;
 
     return schemeAndHost + portPart;
 }