Spaces:
Running
Running
File size: 1,158 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 26 27 28 29 | # Backend dev server with WORKING hot reload on Windows.
#
# uvicorn's built-in `--reload` is unreliable on Windows: it detects file
# changes ("Reloading...") but often fails to actually restart the worker,
# so it silently keeps serving stale code. This wraps uvicorn in
# `watchfiles`, which does a clean full process restart on every change.
#
# Usage (from the backend/ folder):
# .\dev.ps1 # app.main:app on 127.0.0.1:7860, watching .\app
# .\dev.ps1 -Port 8000 # different port
# .\dev.ps1 -App pkg.main:app -Watch pkg
#
# Requires `watchfiles` (bundled with uvicorn[standard], or `pip install watchfiles`).
param(
[string]$App = "app.main:app",
[int]$Port = 7860,
[string]$Watch = "app",
[string]$BindHost = "127.0.0.1"
)
$ErrorActionPreference = "Stop"
# Prefer the project venv's interpreter if present.
$py = if (Test-Path ".venv\Scripts\python.exe") { ".venv\Scripts\python.exe" } else { "python" }
Write-Host "watchfiles -> uvicorn $App on http://$BindHost`:$Port (watching .\$Watch)" -ForegroundColor Cyan
& $py -m watchfiles "$py -m uvicorn $App --host $BindHost --port $Port" $Watch
|