#!/usr/bin/env bash # Backend dev server with hot reload via watchfiles (cross-platform). # # Equivalent to dev.ps1. uvicorn's built-in --reload is unreliable on # Windows; watchfiles does a clean full process restart on every change # and works the same everywhere. # # Usage (from the backend/ folder): # ./dev.sh # app.main:app on 127.0.0.1:7860, watching ./app # ./dev.sh app.main:app 8000 app # # Requires watchfiles (bundled with uvicorn[standard], or pip install watchfiles). set -euo pipefail APP="${1:-app.main:app}" PORT="${2:-7860}" WATCH="${3:-app}" BIND_HOST="${4:-127.0.0.1}" PY=".venv/bin/python" [ -x "$PY" ] || PY="python" echo "watchfiles -> uvicorn $APP on http://$BIND_HOST:$PORT (watching ./$WATCH)" exec "$PY" -m watchfiles "$PY -m uvicorn $APP --host $BIND_HOST --port $PORT" "$WATCH"