#!/bin/sh
# Start FastAPI backend + Next.js frontend in the same container.
# Both processes log to stdout/stderr so Docker captures everything.

set -e

echo "[start.sh] Starting FastAPI backend on :8000 ..."
uvicorn web.app:app --host 127.0.0.1 --port 8000 --workers 1 2>&1 &
UVICORN_PID=$!

# Give uvicorn a moment to start (or crash)
sleep 2

if ! kill -0 $UVICORN_PID 2>/dev/null; then
  echo "[start.sh] ERROR: uvicorn failed to start!"
  # Don't exit — let Node.js run so the UI is accessible for debugging
fi

echo "[start.sh] Starting Next.js frontend on :3000 ..."
node server.js
