File size: 836 Bytes
c20b679
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/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"