Implement environment variable setup for frontend; create .env.production and .env.development files if they don't exist, and update API URLs in frontend components to use dynamic API_BASE_URL for improved configuration management.

This commit is contained in:
Torsten Schulz (local)
2025-10-18 23:36:31 +02:00
parent b066ffdeb4
commit efbb699b4b
25 changed files with 577 additions and 41 deletions

View File

@@ -214,6 +214,39 @@ setup_frontend() {
print_info "Installiere Frontend-Dependencies..."
npm install
# .env.production erstellen falls nicht vorhanden
if [ ! -f ".env.production" ]; then
print_info "Erstelle .env.production..."
cat > .env.production << 'EOF'
# TimeClock v3 - Frontend Production Environment
# API Base URL (relativ, da Apache als Proxy dient)
VITE_API_URL=/api
EOF
print_success ".env.production erstellt"
else
print_success ".env.production bereits vorhanden"
fi
# .env.development erstellen falls nicht vorhanden (für lokale Entwicklung)
if [ ! -f ".env.development" ]; then
print_info "Erstelle .env.development..."
cat > .env.development << 'EOF'
# TimeClock v3 - Frontend Development Environment
VITE_API_URL=http://localhost:3010/api
EOF
print_success ".env.development erstellt"
fi
# Prüfe ob api.js existiert
if [ ! -f "src/config/api.js" ]; then
print_warning "src/config/api.js fehlt! Bitte git pull ausführen."
exit 1
fi
# Alte dist/ löschen für sauberen Build
print_info "Lösche alten Build..."
rm -rf dist/
print_info "Erstelle Produktions-Build..."
npm run build
@@ -222,6 +255,14 @@ setup_frontend() {
exit 1
fi
# Prüfe ob localhost:3010 noch im Build ist
if grep -r "localhost:3010" dist/ > /dev/null 2>&1; then
print_warning "⚠️ localhost:3010 noch im Build gefunden - eventuell falsches .env verwendet"
print_info "Prüfe .env.production: $(cat .env.production 2>/dev/null || echo 'nicht gefunden')"
else
print_success "✅ Build verwendet korrekte API-URL"
fi
print_success "Frontend Build erstellt!"
}
@@ -390,15 +431,40 @@ do_update() {
cd $BACKEND_DIR
npm install --production
# Frontend neu bauen
# Frontend aktualisieren
print_info "Aktualisiere Frontend..."
cd $FRONTEND_DIR
# .env.production prüfen/erstellen
if [ ! -f ".env.production" ]; then
print_info "Erstelle .env.production..."
cat > .env.production << 'EOF'
# TimeClock v3 - Frontend Production Environment
VITE_API_URL=/api
EOF
fi
npm install
# Sauberer Build
rm -rf dist/
npm run build
# Prüfe Build
if grep -r "localhost:3010" dist/ > /dev/null 2>&1; then
print_warning "⚠️ localhost:3010 noch im Build - bitte prüfen"
fi
# Service neu starten
restart_backend
# Apache Cache leeren
if [ "$WEBSERVER" = "apache2" ]; then
sudo systemctl reload apache2
else
sudo systemctl reload nginx
fi
print_success "Update abgeschlossen!"
}