-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.sh
More file actions
executable file
·104 lines (92 loc) · 3.07 KB
/
Copy pathstart.sh
File metadata and controls
executable file
·104 lines (92 loc) · 3.07 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env bash
#
# Webhook Tester — One command to run everything
#
# Usage:
# ./start.sh # Dev mode (hot reload)
# ./start.sh prod # Production (single Docker container for server)
# ./start.sh --port 4200 # Custom port
#
# Stop: ./stop.sh or Ctrl+C
set -e
cd "$(dirname "$0")"
PORT=4100
MODE="dev"
while [[ $# -gt 0 ]]; do
case "$1" in
prod|production) MODE="prod"; shift ;;
--port) PORT="$2"; shift 2 ;;
--port=*) PORT="${1#*=}"; shift ;;
-h|--help)
echo ""
echo " Usage:"
echo " ./start.sh Dev (hot reload + DB in Docker)"
echo " ./start.sh prod Production (single container for server)"
echo " ./start.sh --port 4200 Custom port"
echo ""
exit 0
;;
*) echo "Unknown: $1"; exit 1 ;;
esac
done
# Check Docker
if ! command -v docker &>/dev/null; then
echo " ERROR: Docker not installed. https://docs.docker.com/get-docker/"; exit 1
fi
if ! docker info &>/dev/null; then
echo " ERROR: Docker not running. Start Docker Desktop."; exit 1
fi
# ── Production: single container (app + DB) ──────────────────
if [ "$MODE" = "prod" ]; then
echo ""
echo " Building production container (app + DB)..."
docker build -t webhook-tester .
echo ""
echo " Starting..."
docker run -d --name webhook-tester \
-p $PORT:4100 \
-v webhook-tester-data:/var/lib/postgresql/data \
webhook-tester
echo ""
echo " Webhook Tester (Production)"
echo " http://localhost:$PORT"
echo ""
echo " Logs: docker logs -f webhook-tester"
echo " Stop: ./stop.sh prod"
echo ""
exit 0
fi
# ── Dev: DB in Docker, app runs locally ──────────────────────
# Start PostgreSQL
if ! docker compose ps db 2>/dev/null | grep -q "running"; then
echo " Starting PostgreSQL..."
docker compose up -d db
echo -n " Waiting for DB"
for i in $(seq 1 20); do
if docker compose exec -T db pg_isready -U webhook -d webhook_tester &>/dev/null; then
echo " ready."; break
fi
echo -n "."; sleep 1
[ "$i" -eq 20 ] && echo " timeout!" && exit 1
done
else
echo " PostgreSQL already running."
fi
# Setup
[ ! -f ".env" ] && cp .env.example .env && echo " Created .env"
[ ! -d "node_modules" ] && echo " Installing dependencies..." && npm install
[ ! -d "node_modules/.prisma/client" ] && npx prisma generate
# Migrations
echo " Running migrations..."
source .env 2>/dev/null || true
DATABASE_URL="${DATABASE_URL:-postgres://webhook:webhook_local@localhost:5433/webhook_tester}" npx prisma db push 2>&1 | grep -v "^$" | sed 's/^/ /'
# Kill existing
EXISTING=$(lsof -ti:$PORT 2>/dev/null || true)
[ -n "$EXISTING" ] && echo "$EXISTING" | xargs kill -9 2>/dev/null || true
rm -f .next/dev/lock
echo ""
echo " Webhook Tester (Dev)"
echo " http://localhost:$PORT"
echo " Webhook URL: http://localhost:$PORT/api/webhook/{slug}"
echo ""
DATABASE_URL="${DATABASE_URL:-postgres://webhook:webhook_local@localhost:5433/webhook_tester}" PORT=$PORT npx next dev --webpack -p "$PORT"