Running `pnpm dev` alone gave ECONNREFUSED on every request, because nothing was listening on :7788. Two separate causes: - the backend simply was not running, and - Vite bound [::1]:5173 while the proxy target was "localhost", which Node resolves to ::1 first. The Go server binds IPv4, so even with the backend up the proxy could fail before falling back. - vite.config.ts: proxy target is now 127.0.0.1 explicitly and overridable via VELLUM_API; server.host is true so both stacks are served. - scripts/dev.sh + `make dev`: builds the backend, waits for /healthz, starts Vite, and stops the backend on exit. Ctrl-C tears down both. - README documents that running Vite alone needs the backend already up.
61 lines
1.7 KiB
Bash
Executable file
61 lines
1.7 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
# Run the backend and the Vite dev server together.
|
|
#
|
|
# ./scripts/dev.sh
|
|
#
|
|
# The Go server runs in the background; the Vite dev server runs in the
|
|
# foreground. Ctrl-C stops both. Vite proxies /api to the Go server, so the
|
|
# browser sees one origin and sessions behave exactly as in production.
|
|
set -euo pipefail
|
|
|
|
cd "$(dirname "$0")/.."
|
|
|
|
# A local preview instance, so this works on a fresh clone without touching
|
|
# your real media or your real database.
|
|
export VELLUM_DATA_DIR="${VELLUM_DATA_DIR:-$PWD/demo/data}"
|
|
export VELLUM_CONFIG_DIR="${VELLUM_CONFIG_DIR:-$PWD/demo/config}"
|
|
export VELLUM_LISTEN="${VELLUM_LISTEN:-127.0.0.1:7788}"
|
|
export VELLUM_ADMIN_USER="${VELLUM_ADMIN_USER:-admin}"
|
|
export VELLUM_ADMIN_PASSWORD="${VELLUM_ADMIN_PASSWORD:-vellumdemo}"
|
|
export VELLUM_LOG_LEVEL="${VELLUM_LOG_LEVEL:-info}"
|
|
|
|
if ! command -v go >/dev/null 2>&1; then
|
|
export PATH="$PATH:/usr/lib/golang/bin"
|
|
fi
|
|
|
|
echo "building backend..."
|
|
CGO_ENABLED=0 go build -trimpath -o vellum ./cmd/vellum
|
|
|
|
echo "starting backend on ${VELLUM_LISTEN}"
|
|
./vellum &
|
|
BACKEND=$!
|
|
|
|
cleanup() {
|
|
echo
|
|
echo "stopping backend..."
|
|
kill "$BACKEND" 2>/dev/null || true
|
|
wait "$BACKEND" 2>/dev/null || true
|
|
}
|
|
trap cleanup EXIT INT TERM
|
|
|
|
# Wait for the API to answer before handing over to Vite, so the first page
|
|
# load does not race the backend's startup.
|
|
for _ in $(seq 1 50); do
|
|
if curl -fsS -m 1 "http://${VELLUM_LISTEN#*:}/healthz" >/dev/null 2>&1; then
|
|
break
|
|
fi
|
|
if ! kill -0 "$BACKEND" 2>/dev/null; then
|
|
echo "backend exited during startup" >&2
|
|
exit 1
|
|
fi
|
|
sleep 0.1
|
|
done
|
|
|
|
echo
|
|
echo "backend: http://${VELLUM_LISTEN} (${VELLUM_ADMIN_USER} / ${VELLUM_ADMIN_PASSWORD})"
|
|
echo "frontend: http://localhost:5173"
|
|
echo
|
|
|
|
cd web
|
|
pnpm install --silent
|
|
pnpm dev
|