8000 fix(dev): let the API hot reload while the web app is open by adeelahmad · Pull Request #51 · adeelahmad/lense · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,7 @@ cython_debug/
archive-data/
fastapi_backend/archive.yaml
fastapi_backend/archive-data/

# The schema the dev API writes for the dev web app (docker-compose.yml); nextjs-frontend/openapi.json is the tracked one
local-shared-data/*
!local-shared-data/.gitkeep
8 changes: 6 additions & 2 deletions fastapi_backend/start.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#!/bin/bash
# Development server: API with hot reload, plus the watcher that regenerates the OpenAPI schema for the frontend.
# Uvicorn, not `fastapi dev`: a reload waits for open connections to close, and the web app keeps its event stream
# (/api/v1/events) open, so without a graceful-shutdown timeout a reload never finishes. Only app/ is watched, not a
# local .venv or the tests.
# Both stop when this script is told to (docker stop sends TERM; as a container's first process, bash would otherwise
# ignore it and be killed ten seconds later).
stop() { kill $(jobs -p) 2>/dev/null; wait; }
trap 'stop; exit 0' TERM INT
UVICORN_ARGS="--host 0.0.0.0 --port 8000 --reload --reload-dir app --timeout-graceful-shutdown 3"

if [ -f /.dockerenv ]; then
echo "Running in Docker"
fastapi dev app/main.py --host 0.0.0.0 --port 8000 --reload &
uvicorn app.main:app $UVICORN_ARGS &
python watcher.py &
# If either stops, so does the container, rather than looking up with no API behind it
# (wait -n needs bash 4.3; macOS ships 3.2, so outside Docker this waits for both)
Expand All @@ -17,7 +21,7 @@ if [ -f /.dockerenv ]; then
fi

echo "Running locally with uv"
uv run fastapi dev app/main.py --host 0.0.0.0 --port 8000 --reload &
uv run uvicorn app.main:app $UVICORN_ARGS &
uv run python watcher.py &

wait
Empty file added local-shared-data/.gitkeep
Empty file.
Loading
Loading
0