Spaces:
Sleeping
Sleeping
| # 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 | |