Files
roa2web-service-auto/frontend.sh
Marius Mutu d507a81b0a feat: Implement unified Vue SPA with granular service control
Consolidate Reports and Data Entry apps into a single Vue.js SPA with:

Architecture:
- Module-based structure with lazy-loaded routes (@reports, @data-entry)
- Error boundaries per module to prevent cascade failures
- Dual API proxy in Vite for microservices (reports:8001, data-entry:8003)
- Pinia store factories for shared auth, company, and period stores
- Vite path aliases for clear module boundaries (@shared, @reports, @data-entry)

Service Management:
- Granular service control scripts (backend-reports.sh, backend-data-entry.sh, bot.sh, frontend.sh)
- 87% faster frontend restart: 7s vs 53s full restart
- 38% faster full startup: 33s vs 53s via parallel backend initialization
- Enhanced start-dev.sh with proper service timeouts (OCR: 30s, Vite: 15s, Bot: 10s)
- status.sh for comprehensive health checks

Features:
- Auto-select first company on login with period auto-load
- Hamburger menu with feature toggle support
- JWT token auto-injection via axios interceptors
- Unified header with company/period selectors
- IIS web.config for production deployment with multi-API routing

UX Improvements:
- Vue watchers for reactive company/period loading
- Lazy store initialization with graceful error handling
- Period persistence per user+company in localStorage
- Feature flags for optional modules

Deployment:
- Single IIS site serves unified frontend with API proxy rules
- Maintains separate backend processes for microservices
- Windows line ending fixes (.env CRLF → LF conversion)

Stats: 112 files changed, 38,342 insertions(+), 2,342 deletions(-)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-24 19:06:23 +02:00

152 lines
3.5 KiB
Bash

#!/bin/bash
# Frontend Service Control Script for ROA2WEB Unified App
# Manages the Vite dev server on port 3000
# Script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT_DIR="$SCRIPT_DIR"
# Source helper functions
source "$SCRIPT_DIR/scripts/service-helpers.sh"
# Service configuration
SERVICE_NAME="Frontend Unified"
PORT=3000
LOG_FILE="/tmp/vite-unified.log"
NODE_MODULES_DIR="$ROOT_DIR/node_modules"
# Function to start frontend
start_frontend() {
print_header "Starting $SERVICE_NAME"
# Check if port is already in use
if ! check_port_available $PORT "$SERVICE_NAME"; then
print_warning "$SERVICE_NAME may already be running"
print_info "Use './frontend.sh status' to check or './frontend.sh stop' to stop it"
return 1
fi
# Check node_modules
if [ ! -d "$NODE_MODULES_DIR" ]; then
print_info "node_modules not found, running npm install..."
cd "$ROOT_DIR"
npm install
if [ $? -ne 0 ]; then
print_error "npm install failed"
return 1
fi
fi
# Start Vite dev server
print_info "Starting Vite dev server..."
cd "$ROOT_DIR"
# Start in background with nohup
nohup npm run dev > "$LOG_FILE" 2>&1 &
local pid=$!
print_info "Started with PID: $pid"
print_info "Log file: $LOG_FILE"
# Wait for port to be ready
if wait_for_port $PORT "$SERVICE_NAME" 10; then
print_success "$SERVICE_NAME started successfully!"
echo ""
print_info "🌐 Frontend URLs:"
echo " • Local: http://localhost:$PORT"
echo " • Network: http://$(hostname -I | awk '{print $1}'):$PORT"
echo ""
print_info "📄 View logs: tail -f $LOG_FILE"
return 0
else
print_error "Failed to start $SERVICE_NAME (timeout waiting for port $PORT)"
print_info "Check logs: tail -20 $LOG_FILE"
return 1
fi
}
# Function to stop frontend
stop_frontend() {
print_header "Stopping $SERVICE_NAME"
kill_port $PORT "$SERVICE_NAME"
# Clean up log file (optional - comment out if you want to keep logs)
# if [ -f "$LOG_FILE" ]; then
# rm "$LOG_FILE"
# print_info "Cleaned up log file"
# fi
return 0
}
# Function to restart frontend
restart_frontend() {
print_header "Restarting $SERVICE_NAME"
stop_frontend
sleep 2
start_frontend
return $?
}
# Function to show frontend status
status_frontend() {
print_header "$SERVICE_NAME Status"
if check_service_status $PORT "$SERVICE_NAME"; then
echo ""
print_info "Service is healthy"
# Show recent logs
if [ -f "$LOG_FILE" ]; then
echo ""
tail_logs "$LOG_FILE" 10
fi
return 0
else
echo ""
print_warning "Service is not running"
# Show last logs if available
if [ -f "$LOG_FILE" ]; then
echo ""
print_info "Last logs before shutdown:"
tail_logs "$LOG_FILE" 10
fi
return 1
fi
}
# Main script logic
case "${1:-}" in
start)
start_frontend
;;
stop)
stop_frontend
;;
restart)
restart_frontend
;;
status)
status_frontend
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
echo ""
echo "Commands:"
echo " start - Start the frontend dev server"
echo " stop - Stop the frontend dev server"
echo " restart - Restart the frontend dev server"
echo " status - Show frontend status and recent logs"
echo ""
echo "Examples:"
echo " ./frontend.sh start # Start frontend"
echo " ./frontend.sh restart # Quick restart (most common for dev)"
echo " ./frontend.sh status # Check if running"
exit 1
;;
esac