Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): honor VITE_API_URL for split-origin deployments (#91) (#231)

Yudhi Armyndharis3178e1600c26
diff --git a/dashboard/README.md b/dashboard/README.md
index f029b0d00..9d5e8374e 100644
--- a/dashboard/README.md
+++ b/dashboard/README.md
@@ -78,10 +78,16 @@ dashboard/
## πŸ”— API Connection
-The dashboard connects to the OpenWA API backend. Configure the API URL in environment variables:
+By default the dashboard calls the API on the **same origin** it is served from (the
+single-container setup), so no configuration is needed.
+
+For a **split-origin** deployment (dashboard hosted separately from the API), set the API
+**origin** at build time β€” the `/api` prefix is appended automatically:
```bash
VITE_API_URL=http://localhost:2785
+# real-time events (WebSocket) origin; defaults to the page origin
+VITE_WS_URL=http://localhost:2785
```
## πŸ“„ License
diff --git a/dashboard/src/services/api.ts b/dashboard/src/services/api.ts
index 19179f26e..e670425ec 100644
--- a/dashboard/src/services/api.ts
+++ b/dashboard/src/services/api.ts
@@ -1,7 +1,14 @@
// API Service Layer for OpenWA Dashboard
// Centralized API client with TypeScript types
-const API_BASE_URL = '/api';
+// Resolve the API base URL. By default this is the same-origin relative path '/api',
+// correct when the dashboard and API are served from the same origin (the default
+// single-container setup). For a split-origin deployment (dashboard hosted separately
+// from the API), set VITE_API_URL at build time to the API ORIGIN β€” e.g.
+// `VITE_API_URL=https://gateway.example.com` β€” and the '/api' prefix is appended here.
+// Previously VITE_API_URL was documented but never read, so the dashboard always called
+// same-origin '/api' and a split deployment failed with "Invalid API Key" (#91).
+const API_BASE_URL = `${(import.meta.env.VITE_API_URL ?? '').replace(/\/+$/, '')}/api`;
// =============================================================================
// Types