-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdev.sh
More file actions
executable file
·46 lines (39 loc) · 839 Bytes
/
dev.sh
File metadata and controls
executable file
·46 lines (39 loc) · 839 Bytes
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
#!/bin/bash
# Local dev: starts API + Caddy
# Press 'r' to restart the API
cd "$(dirname "$0")"
ROOT="$PWD"
export PORT=${PORT:-8080}
API_PID=""
start_api() {
if [ -n "$API_PID" ]; then
kill -- -"$API_PID" 2>/dev/null || true
wait "$API_PID" 2>/dev/null || true
fi
echo "Starting API on :8090..."
set -m
(cd api && go run . -db "$ROOT/sayless.db" -addr 127.0.0.1:8090) &
API_PID=$!
set +m
}
CADDY_PID=""
cleanup() {
kill -9 -- -"$API_PID" 2>/dev/null || true
kill -9 "$CADDY_PID" 2>/dev/null || true
exit 0
}
trap cleanup INT TERM
start_api
echo "Starting Caddy on :$PORT..."
caddy run &
CADDY_PID=$!
echo ""
echo "Press 'r' to restart API"
echo ""
while true; do
read -rsn1 key
if [ "$key" = "r" ]; then
echo "Restarting API..."
start_api
fi
done