Refactor daemon URL configuration and enhance logging

- Improved fallback logic for daemon URL based on hostname and environment
- Added detailed logging for daemon connection status and environment settings
- Streamlined handling of environment variables for better clarity
This commit is contained in:
Torsten Schulz (local)
2025-11-18 08:50:25 +01:00
parent 016a37c116
commit 27b675cb19
3 changed files with 170 additions and 78 deletions

View File

@@ -254,21 +254,38 @@ const store = createStore({
state.daemonConnecting = true;
// Daemon URL für lokale Entwicklung und Produktion
let daemonUrl = import.meta.env.VITE_DAEMON_SOCKET;
// Vite bindet Umgebungsvariablen zur Build-Zeit ein, daher Fallback-Logik basierend auf Hostname
const hostname = window.location.hostname;
const isLocalhost = hostname === 'localhost' || hostname === '127.0.0.1' || hostname === '::1' || hostname === '[::1]';
const isProduction = hostname === 'www.your-part.de' || hostname.includes('your-part.de');
// Versuche Umgebungsvariable zu lesen (kann undefined sein, wenn nicht zur Build-Zeit gesetzt)
let daemonUrl = import.meta.env?.VITE_DAEMON_SOCKET;
console.log('[Daemon] Umgebungsvariable VITE_DAEMON_SOCKET:', daemonUrl);
console.log('[Daemon] DEV-Modus:', import.meta.env.DEV);
console.log('[Daemon] Hostname:', window.location.hostname);
console.log('[Daemon] DEV-Modus:', import.meta.env?.DEV);
console.log('[Daemon] Hostname:', hostname);
console.log('[Daemon] IsLocalhost:', isLocalhost);
console.log('[Daemon] IsProduction:', isProduction);
// Nur wenn Umgebungsvariable NICHT gesetzt ist, Fallback-Logik verwenden
if (!daemonUrl) {
// Für lokale Entwicklung: direkte Daemon-Verbindung
if (import.meta.env.DEV || window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1') {
daemonUrl = 'ws://localhost:4551';
} else {
// Fallback für Produktion
// Wenn Umgebungsvariable nicht gesetzt ist oder leer, verwende Fallback-Logik
if (!daemonUrl || (typeof daemonUrl === 'string' && daemonUrl.trim() === '')) {
if (isLocalhost) {
// Für lokale Entwicklung: direkte Daemon-Verbindung
daemonUrl = 'ws://127.0.0.1:4551';
console.log('[Daemon] Verwende localhost-Fallback');
} else if (isProduction) {
// Für Produktion: wss://www.your-part.de:4551
daemonUrl = 'wss://www.your-part.de:4551';
console.log('[Daemon] Verwende Produktions-Fallback');
} else {
// Fallback: basierend auf Protokoll
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
daemonUrl = `${protocol}//${hostname}:4551`;
console.log('[Daemon] Verwende generischen Fallback basierend auf Hostname');
}
} else {
console.log('[Daemon] Verwende Umgebungsvariable');
}
console.log('[Daemon] Finale Daemon-URL:', daemonUrl);