-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstart.sh
More file actions
executable file
·75 lines (62 loc) · 3.7 KB
/
Copy pathstart.sh
File metadata and controls
executable file
·75 lines (62 loc) · 3.7 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
#!/usr/bin/env bash
set -e
ROOT="$(cd "$(dirname "$0")" && pwd)"
VENV="$ROOT/.venv"
BACKEND="$ROOT/backend"
FRONTEND="$ROOT/frontend"
# ── Colour helpers ────────────────────────────────────────────────────────────
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; CYAN='\033[0;36m'; NC='\033[0m'
info() { echo -e "${CYAN}[start]${NC} $*"; }
success() { echo -e "${GREEN}[start]${NC} $*"; }
warn() { echo -e "${YELLOW}[start]${NC} $*"; }
error() { echo -e "${RED}[start]${NC} $*"; exit 1; }
# ── Validate .venv ────────────────────────────────────────────────────────────
[ -d "$VENV" ] || error ".venv not found at $VENV — run: python -m venv .venv && .venv/bin/pip install -r backend/requirements.txt"
# ── Validate .env ─────────────────────────────────────────────────────────────
if [ ! -f "$BACKEND/.env" ]; then
warn "No $BACKEND/.env found — copying from .env.example"
cp "$BACKEND/.env.example" "$BACKEND/.env"
warn "Edit $BACKEND/.env and set GOOGLE_CLOUD_PROJECT before running again."
exit 1
fi
# ── Check node ───────────────────────────────────────────────────────────────
command -v node >/dev/null 2>&1 || error "node not found — install from https://nodejs.org"
# ── Activate venv ─────────────────────────────────────────────────────────────
source "$VENV/bin/activate"
success "Activated .venv ($(python --version))"
# ── Cleanup on exit ───────────────────────────────────────────────────────────
BACKEND_PID=""
FRONTEND_PID=""
cleanup() {
echo ""
info "Shutting down..."
[ -n "$BACKEND_PID" ] && kill "$BACKEND_PID" 2>/dev/null && info "Backend stopped"
[ -n "$FRONTEND_PID" ] && kill "$FRONTEND_PID" 2>/dev/null && info "Frontend stopped"
exit 0
}
trap cleanup INT TERM
# ── Start backend ─────────────────────────────────────────────────────────────
info "Starting backend on http://localhost:8000 ..."
cd "$BACKEND"
uvicorn main:app --host 0.0.0.0 --port 8000 --reload &
BACKEND_PID=$!
cd "$ROOT"
# Give uvicorn a moment to bind
sleep 1
# ── Start frontend ────────────────────────────────────────────────────────────
info "Starting frontend on http://localhost:8080 ..."
cd "$FRONTEND"
npx vite &
FRONTEND_PID=$!
cd "$ROOT"
# ── Summary ───────────────────────────────────────────────────────────────────
echo ""
success "TaleWeaver is running!"
echo -e " ${CYAN}Frontend${NC} → http://localhost:8080"
echo -e " ${CYAN}Backend${NC} → http://localhost:8000"
echo -e " ${CYAN}Health${NC} → http://localhost:8000/api/health"
echo -e " ${CYAN}WS${NC} → ws://localhost:8000/ws/story"
echo ""
info "Press Ctrl+C to stop both servers."
echo ""
wait