Commit abcbbea3 authored by Hendrik Garske's avatar Hendrik Garske

Fix: Entferne window-Referenz und verbessere Fehlermeldungen

parent 6d6ca448
...@@ -67,12 +67,20 @@ export class WgApiClient { ...@@ -67,12 +67,20 @@ export class WgApiClient {
private async request<T>(endpoint: string, options: RequestInit = {}): Promise<T> { private async request<T>(endpoint: string, options: RequestInit = {}): Promise<T> {
// Liste möglicher Backend-URLs zum Ausprobieren // Liste möglicher Backend-URLs zum Ausprobieren
// Hinweis: Port 51821 ist der Standard-Port für wg-easy Web-UI
// Wenn das Backend auf einem anderen Port läuft, muss WG_API_URL als Environment Variable gesetzt werden
const possibleUrls = [ const possibleUrls = [
this.baseUrl, // Zuerst die konfigurierte URL versuchen this.baseUrl, // Zuerst die konfigurierte URL versuchen
'http://localhost:51821', 'http://localhost:51821',
'http://127.0.0.1:51821', 'http://127.0.0.1:51821',
'http://localhost:51820', // Alternative Port
'http://wg-easy:51821', 'http://wg-easy:51821',
'http://wg-easy:51820',
'http://srv-captain--wg-easy:51821', 'http://srv-captain--wg-easy:51821',
'http://srv-captain--wg-easy:51820',
// Versuche auch mögliche CapRover Service-Namen
'http://srv-captain--corex-wg-easy:51821',
'http://srv-captain--corex-wg-easy:51820',
] ]
let lastError: Error | null = null let lastError: Error | null = null
...@@ -129,8 +137,14 @@ export class WgApiClient { ...@@ -129,8 +137,14 @@ export class WgApiClient {
} }
} }
// All URLs failed // All URLs failed - provide helpful error message
throw new Error(`Failed to connect to WG API. Tried: ${possibleUrls.join(', ')}. Last error: ${lastError?.message || 'Unknown error'}`) const triedUrls = possibleUrls.filter((url, index, self) => self.indexOf(url) === index) // Remove duplicates
throw new Error(
`Failed to connect to WG API Backend. ` +
`Tried URLs: ${triedUrls.join(', ')}. ` +
`Last error: ${lastError?.message || 'Unknown error'}. ` +
`Please ensure the wg-easy backend is running and set WG_API_URL environment variable if it's on a different URL/port.`
)
} }
async getStats(): Promise<WgStats> { async getStats(): Promise<WgStats> {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment