Files
plantillas-proyectos/scripts/frontend-entrypoint.sh

45 lines
1.3 KiB
Bash
Executable File

#!/bin/sh
set -e
# Script de inicialización para el Frontend SvelteKit
# Espera a que el backend esté disponible antes de iniciar
echo "=========================================="
echo "Frontend SvelteKit - Inicialización"
echo "=========================================="
# Función para esperar al backend
wait_for_backend() {
local url=$1
local max_attempts=30
local attempt=1
echo "Esperando a que el Backend esté disponible en ${url}..."
while [ $attempt -le $max_attempts ]; do
if wget -q -O /dev/null "${url}/health" 2>/dev/null; then
echo "✓ Backend está listo"
return 0
fi
echo "Backend no está listo aún... (intento $attempt/$max_attempts)"
attempt=$((attempt + 1))
sleep 3
done
echo "⚠ WARNING: Backend no estuvo disponible, continuando de todas formas"
return 0
}
# Esperar al backend
# En Docker, usamos el nombre del servicio. En desarrollo local, PUBLIC_API_URL apunta a localhost
BACKEND_HEALTH_URL="${BACKEND_INTERNAL_URL:-http://backend:8000/api}"
wait_for_backend "${BACKEND_HEALTH_URL}"
echo "=========================================="
echo "Iniciando aplicación SvelteKit..."
echo "=========================================="
# Ejecutar el comando que se pasó al contenedor
exec "$@"