Spaces:
Sleeping
Sleeping
File size: 4,003 Bytes
cf93910 | 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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | #!/usr/bin/env pwsh
# ============================================================
# SanketSetu β start both servers with a single command
# Usage: .\start.ps1
#
# Starts:
# Backend β http://localhost:8000
# Frontend β http://localhost:5173
# ============================================================
$ROOT = $PSScriptRoot
$VENV_PY = "$ROOT\.venv\Scripts\python.exe"
$VENV_UV = "$ROOT\.venv\Scripts\uvicorn.exe"
$BACKEND = "$ROOT\backend"
$FRONTEND = "$ROOT\frontend"
# ββ sanity checks ββββββββββββββββββββββββββββββββββββββββββ
if (-not (Test-Path $VENV_UV)) {
Write-Error "venv not found. Run: python -m venv .venv then .venv\Scripts\pip install -r backend\requirements.txt"
exit 1
}
if (-not (Test-Path "$FRONTEND\node_modules")) {
Write-Host "β Installing frontend depsβ¦" -ForegroundColor Cyan
Push-Location $FRONTEND
npm install
Pop-Location
}
# ββ port check & kill βββββββββββββββββββββββββββββββββββββ
foreach ($port in @(8000, 5173)) {
$pid_ = (netstat -ano | Select-String ":$port .*LISTENING") -replace '.*\s(\d+)$','$1' | Select-Object -Last 1
if ($pid_) {
Write-Host "[port $port] Freeing PID $pid_β¦" -ForegroundColor Yellow
taskkill /PID $pid_ /F 2>$null | Out-Null
Start-Sleep -Milliseconds 500
}
}
# ββ start backend in a new window βββββββββββββββββββββββββ
Write-Host "π Starting backend on :8000 β¦" -ForegroundColor Green
$backendJob = Start-Process -FilePath "powershell.exe" -ArgumentList `
"-NoProfile", "-Command",
"Set-Location '$BACKEND'; & '$VENV_UV' app.main:app --port 8000" `
-PassThru -WindowStyle Normal
# ββ wait for backend ready (max 3 min) ββββββββββββββββββββ
Write-Host "β³ Waiting for backend to load models (may take ~2 min)β¦" -ForegroundColor Cyan
$ready = $false
for ($i = 0; $i -lt 36; $i++) {
Start-Sleep -Seconds 5
try {
$r = Invoke-WebRequest "http://localhost:8000/health" -UseBasicParsing -TimeoutSec 3 -ErrorAction Stop
Write-Host "β
Backend ready: $($r.Content)" -ForegroundColor Green
$ready = $true; break
} catch { Write-Host " β¦waiting ($([int]($i*5+5))s)" }
}
if (-not $ready) { Write-Warning "Backend didn't respond in time. Check the backend window." }
# ββ start frontend βββββββββββββββββββββββββββββββββββββββββ
Write-Host "π Starting frontend on :5173 β¦" -ForegroundColor Green
$frontendJob = Start-Process -FilePath "powershell.exe" -ArgumentList `
"-NoProfile", "-Command",
"Set-Location '$FRONTEND'; npm run dev" `
-PassThru -WindowStyle Normal
Start-Sleep -Seconds 3
Write-Host ""
Write-Host "ββββββββββββββββββββββββββββββββββββββββββββ" -ForegroundColor Magenta
Write-Host "β SanketSetu is running! β" -ForegroundColor Magenta
Write-Host "β Frontend : http://localhost:5173 β" -ForegroundColor Magenta
Write-Host "β Backend : http://localhost:8000 β" -ForegroundColor Magenta
Write-Host "β API Docs : http://localhost:8000/docs β" -ForegroundColor Magenta
Write-Host "ββββββββββββββββββββββββββββββββββββββββββββ" -ForegroundColor Magenta
Write-Host ""
Write-Host "Press any key to stop both serversβ¦" -ForegroundColor Yellow
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
Stop-Process -Id $backendJob.Id -Force -ErrorAction SilentlyContinue
Stop-Process -Id $frontendJob.Id -Force -ErrorAction SilentlyContinue
Write-Host "Servers stopped." -ForegroundColor Red
|