40 lines
1.0 KiB
Bash
Executable File
40 lines
1.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Run backend (Go) and frontend (Vite) together; stop both on Ctrl+C
|
|
set -euo pipefail
|
|
|
|
# Always run from repo root
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
cd "$SCRIPT_DIR"
|
|
|
|
BACKEND_ADDR=${BACKEND_ADDR:-0.0.0.0:8080}
|
|
DATA_DIR=${DATA_DIR:-./x-storage}
|
|
|
|
cleanup() {
|
|
echo "\n[dev] Shutting down..."
|
|
# Kill all background jobs spawned by this script
|
|
jobs -p | xargs -r kill 2>/dev/null || true
|
|
# Extra wait to ensure graceful shutdown
|
|
wait || true
|
|
}
|
|
trap cleanup INT TERM
|
|
|
|
# Start backend
|
|
(
|
|
echo "[dev] Starting backend on $BACKEND_ADDR (data-dir=$DATA_DIR)"
|
|
go run cmd/server/main.go -debug -address "$BACKEND_ADDR" -data-dir "$DATA_DIR"
|
|
) &
|
|
BACKEND_PID=$!
|
|
|
|
# Start frontend
|
|
(
|
|
echo "[dev] Starting frontend dev server (Vite)"
|
|
npm --prefix frontend run dev
|
|
) &
|
|
FRONTEND_PID=$!
|
|
|
|
echo "[dev] Backend PID: $BACKEND_PID, Frontend PID: $FRONTEND_PID"
|
|
echo "[dev] Press Ctrl+C to stop both..."
|
|
|
|
# Wait for both processes to exit (trap will handle Ctrl+C)
|
|
wait $BACKEND_PID $FRONTEND_PID
|