Files
plantillas-proyectos/frontend/docker-entrypoint.sh
AlexeerCT 1dadcc6482 Fix wait_for_backend function to use the correct URL for health checks
- Updated the health check logic in the wait_for_backend function to use the caller-provided URL directly, eliminating the issue of appending an extra "/health" segment that caused unnecessary delays in the frontend startup.
- Added comments to clarify the changes and their impact on the entrypoint behavior.
2026-04-24 16:30:54 -05:00

45 lines
1.4 KiB
Bash

#!/bin/sh
set -e
# Arranque del contenedor: opcionalmente espera al health del backend, luego ejecuta CMD (pnpm dev / start, …)
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
# NOTA: usar la URL tal cual la pasa el caller. Antes esta función agregaba
# un "/health" extra al final (resultando en /api/health/health → 404), lo
# que provocaba que el entrypoint esperara 30 intentos en vano antes de
# arrancar Vite, sumando ~90 s muertos al arranque del frontend.
if wget -q -O /dev/null "${url}" 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
}
# compose usa INTERNAL_API_URL; alias opcional BACKEND_INTERNAL_URL
_api_base="${INTERNAL_API_URL:-${BACKEND_INTERNAL_URL:-http://backend:8000/api}}"
_api_base="${_api_base%/}"
wait_for_backend "${_api_base}/health"
# En desarrollo (volumen montado) reinstala deps si cambia package.json
if [ "$NODE_ENV" = "development" ]; then
echo "Instalando dependencias (development)..."
CI=true pnpm install
fi
echo "Iniciando: $*"
exec "$@"