RotNot / start.sh
deploy
Deploy RotNot
9580dce
Raw History Blame Contribute Delete
1.29 kB
#!/usr/bin/env bash
# Launch the RotNot dev server (Next.js handles both frontend + API routes in one process)
# and open the browser once it's ready. Override the port with PORT=3101 ./start.sh
set -euo pipefail
cd "$(dirname "$0")"
PORT="${PORT:-3000}"
URL="http://localhost:${PORT}"
if [ ! -f .env ] && [ -f .env.example ]; then
echo "warning: no .env found — copy .env.example to .env and add ANTHROPIC_API_KEY before exercises will work"
fi
if [ ! -d node_modules ]; then
echo "installing dependencies..."
npm install
fi
if [ ! -f dev.db ]; then
echo "no dev.db found — running prisma migrate deploy + seed..."
npx prisma migrate deploy
npx prisma db seed
fi
cleanup() {
if [ -n "${DEV_PID:-}" ] && kill -0 "$DEV_PID" 2>/dev/null; then
kill "$DEV_PID" 2>/dev/null || true
fi
}
trap cleanup EXIT INT TERM
echo "starting next dev on port ${PORT}..."
PORT="$PORT" npm run dev &
DEV_PID=$!
echo "waiting for ${URL} to respond..."
for _ in $(seq 1 60); do
if curl -sf -o /dev/null "$URL"; then
echo "server is up — opening browser"
case "$(uname -s)" in
Darwin) open "$URL" ;;
Linux) xdg-open "$URL" >/dev/null 2>&1 || true ;;
MINGW*|MSYS*|CYGWIN*) start "$URL" ;;
esac
break
fi
sleep 1
done
wait "$DEV_PID"