-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev.sh
More file actions
executable file
·60 lines (48 loc) · 1.68 KB
/
Copy pathdev.sh
File metadata and controls
executable file
·60 lines (48 loc) · 1.68 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
#!/usr/bin/env bash
#
# One-time setup to make this script executable:
# chmod +x "/Users/akhileshbharatham/Documents/GitHub/PulmoSim.py/dev.sh"
#
# Run both backend (FastAPI) and frontend (Vite) together:
# "/Users/akhileshbharatham/Documents/GitHub/PulmoSim.py/dev.sh"
#
# Optional custom ports (defaults: backend 8000, frontend 5173):
# PORT=9000 VITE_PORT=5174 /Users/akhileshbharatham/Documents/GitHub/PulmoSim.py/dev.sh
#
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "$0")" && pwd)"
PORT="${PORT:-8000}"
VITE_PORT="${VITE_PORT:-5173}"
# Optional: activate local venv if present
if [ -f "$ROOT_DIR/.venv/bin/activate" ]; then
# shellcheck source=/dev/null
source "$ROOT_DIR/.venv/bin/activate"
fi
# Free backend port if taken
lsof -nP -iTCP:"$PORT" -sTCP:LISTEN -t 2>/dev/null | xargs -r kill || true
echo "Starting backend on :$PORT ..."
PYTHONPATH="$ROOT_DIR" \
uvicorn server:app --host 0.0.0.0 --port "$PORT" --reload --app-dir "$ROOT_DIR" &
BACK_PID=$!
cleanup() {
echo "\nShutting down..."
kill $BACK_PID $FRONT_PID 2>/dev/null || true
}
trap cleanup INT TERM EXIT
echo "Starting frontend on :$VITE_PORT (API http://localhost:$PORT) ..."
cd "$ROOT_DIR/frontend"
# Ensure API base is set for Vite
echo "VITE_API_BASE=http://localhost:$PORT" > .env
# Install deps if vite is missing
if [ ! -d node_modules ] || [ ! -x node_modules/.bin/vite ]; then
echo "Installing frontend dependencies..."
npm install --no-fund --no-audit
fi
# Launch Vite via npx so it works even if locally not installed
npx vite --port "$VITE_PORT" --strictPort &
FRONT_PID=$!
# Try to open the browser (macOS)
if command -v open >/dev/null 2>&1; then
(sleep 1 && open "http://localhost:$VITE_PORT") &
fi
wait