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