-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart-dev.ps1
More file actions
143 lines (121 loc) · 6.18 KB
/
Copy pathstart-dev.ps1
File metadata and controls
143 lines (121 loc) · 6.18 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env pwsh
# Phobetron - Development Server Startup Script
# This script starts both the backend (FastAPI) and frontend (Vite) servers
Write-Host "`n╔════════════════════════════════════════════════════════════════╗" -ForegroundColor Cyan
Write-Host "║ 🌌 Phobetron - Starting Dev Servers... ║" -ForegroundColor Cyan
Write-Host "╚════════════════════════════════════════════════════════════════╝`n" -ForegroundColor Cyan
# Get the script's directory
$ProjectRoot = $PSScriptRoot
# Backend configuration
$BackendPath = Join-Path $ProjectRoot "backend"
$VenvPython = Join-Path $BackendPath "venv\Scripts\python.exe"
$BackendPort = 8000
# Frontend configuration
$FrontendPath = Join-Path $ProjectRoot "frontend"
$FrontendPort = 3000
# Check if Python venv exists
if (-not (Test-Path $VenvPython)) {
Write-Host "❌ Python virtual environment not found at: $VenvPython" -ForegroundColor Red
Write-Host "Please create a virtual environment in the backend directory." -ForegroundColor Yellow
exit 1
}
# Function to stop existing servers
function Stop-ExistingServers {
Write-Host "🔍 Checking for existing servers..." -ForegroundColor Yellow
# Stop existing Node.js processes (Vite)
Get-Process -Name "node" -ErrorAction SilentlyContinue | Where-Object {
$_.CommandLine -like "*vite*"
} | ForEach-Object {
Write-Host " ⏹️ Stopping existing Vite server (PID: $($_.Id))" -ForegroundColor Yellow
Stop-Process -Id $_.Id -Force -ErrorAction SilentlyContinue
}
# Stop existing Python/Uvicorn processes
Get-Process -Name "python","uvicorn" -ErrorAction SilentlyContinue | Where-Object {
$_.CommandLine -like "*8000*" -or $_.CommandLine -like "*main:app*"
} | ForEach-Object {
Write-Host " ⏹️ Stopping existing backend server (PID: $($_.Id))" -ForegroundColor Yellow
Stop-Process -Id $_.Id -Force -ErrorAction SilentlyContinue
}
Start-Sleep -Seconds 2
Write-Host "✅ Cleanup complete`n" -ForegroundColor Green
}
# Stop any existing servers
Stop-ExistingServers
# Start Backend Server
Write-Host "🚀 Starting Backend API Server..." -ForegroundColor Magenta
Write-Host " 📍 Path: $BackendPath" -ForegroundColor Gray
Write-Host " 🔌 Port: $BackendPort" -ForegroundColor Gray
Write-Host " 🐍 Python: $VenvPython`n" -ForegroundColor Gray
$BackendJob = Start-Job -ScriptBlock {
param($VenvPython, $BackendPath, $BackendPort)
Set-Location $BackendPath
& $VenvPython -m uvicorn app.main:app --reload --port $BackendPort
} -ArgumentList $VenvPython, $BackendPath, $BackendPort
# Wait a moment for backend to start
Start-Sleep -Seconds 3
# Check if backend started successfully
$BackendHealthy = $false
try {
$response = Invoke-WebRequest -Uri "http://localhost:$BackendPort/health" -TimeoutSec 5 -UseBasicParsing
if ($response.StatusCode -eq 200) {
$BackendHealthy = $true
Write-Host "✅ Backend API is healthy!" -ForegroundColor Green
}
} catch {
Write-Host "⚠️ Backend health check failed (it may still be starting...)" -ForegroundColor Yellow
}
Write-Host ""
# Start Frontend Server
Write-Host "🚀 Starting Frontend Vite Server..." -ForegroundColor Cyan
Write-Host " 📍 Path: $FrontendPath" -ForegroundColor Gray
Write-Host " 🔌 Port: $FrontendPort`n" -ForegroundColor Gray
$FrontendJob = Start-Job -ScriptBlock {
param($FrontendPath)
Set-Location $FrontendPath
npm run dev:frontend
} -ArgumentList $FrontendPath
# Wait for frontend to start
Start-Sleep -Seconds 5
# Display status
Write-Host "╔════════════════════════════════════════════════════════════════╗" -ForegroundColor Green
Write-Host "║ ✨ Development Servers Running! ║" -ForegroundColor Green
Write-Host "╚════════════════════════════════════════════════════════════════╝" -ForegroundColor Green
Write-Host ""
Write-Host "🌐 Frontend: " -NoNewline -ForegroundColor Cyan
Write-Host "http://localhost:$FrontendPort" -ForegroundColor White -BackgroundColor DarkBlue
Write-Host "🔌 Backend: " -NoNewline -ForegroundColor Magenta
Write-Host "http://localhost:$BackendPort" -ForegroundColor White -BackgroundColor DarkBlue
Write-Host "📖 API Docs: " -NoNewline -ForegroundColor Yellow
Write-Host "http://localhost:$BackendPort/docs" -ForegroundColor White -BackgroundColor DarkBlue
Write-Host ""
Write-Host "Press Ctrl+C to stop all servers" -ForegroundColor Gray
Write-Host ""
# Keep script running and monitor jobs
try {
while ($true) {
# Check if jobs are still running
if ($BackendJob.State -eq "Failed" -or $BackendJob.State -eq "Stopped") {
Write-Host "❌ Backend server stopped unexpectedly!" -ForegroundColor Red
break
}
if ($FrontendJob.State -eq "Failed" -or $FrontendJob.State -eq "Stopped") {
Write-Host "❌ Frontend server stopped unexpectedly!" -ForegroundColor Red
break
}
# Display job output periodically
Receive-Job -Job $BackendJob -ErrorAction SilentlyContinue | ForEach-Object {
Write-Host "[BACKEND] $_" -ForegroundColor Magenta
}
Receive-Job -Job $FrontendJob -ErrorAction SilentlyContinue | ForEach-Object {
Write-Host "[VITE] $_" -ForegroundColor Cyan
}
Start-Sleep -Seconds 1
}
} finally {
# Cleanup on exit
Write-Host "`n🛑 Stopping servers..." -ForegroundColor Yellow
Stop-Job -Job $BackendJob, $FrontendJob -ErrorAction SilentlyContinue
Remove-Job -Job $BackendJob, $FrontendJob -Force -ErrorAction SilentlyContinue
Stop-ExistingServers
Write-Host "✅ All servers stopped.`n" -ForegroundColor Green
}