Repository navigation
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·72 lines (54 loc) · 1.42 KB
/
Copy pathrun.sh
File metadata and controls
executable file
·72 lines (54 loc) · 1.42 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
#!/bin/bash
set -e
MODE=${1:-dev}
SERVER_DIR="./server"
WEB_DIR="./www"
cleanup() {
echo "🧹 Cleaning up background processes..."
if [ ! -z "$ASTRO_PID" ]; then
kill "$ASTRO_PID" 2>/dev/null || true
fi
}
trap cleanup EXIT
kill -9 $(lsof -t -i:4321) 2>/dev/null || true
rm -rf "$WEB_DIR/.astro"
# ---------------------------------------
# DEV MODE
# ---------------------------------------
if [ "$MODE" = "dev" ]; then
echo "🚧 Starting DEV mode..."
export DEV_MODE=true
export PUBLIC_PB_URL=http://localhost:8090
export PUBLIC_API_URL=http://localhost:4321
# Start PocketBase FIRST
echo "📦 Starting PocketBase..."
(cd "$SERVER_DIR" && go run export.go import.go main.go serve) &
PB_PID=$!
# wait for PocketBase
sleep 2
# Start Astro
echo "🌐 Starting Astro..."
(cd "$WEB_DIR" && npm run dev) &
ASTRO_PID=$!
echo "Astro PID: $ASTRO_PID"
echo "PocketBase PID: $PB_PID"
wait
# ---------------------------------------
# PROD MODE
# ---------------------------------------
elif [ "$MODE" = "prod" ]; then
echo "🚀 Building production release..."
export DEV_MODE=false
# build frontend
(cd "$WEB_DIR" && npm run build)
# copy dist
rm -rf "$SERVER_DIR/dist"
cp -r "$WEB_DIR/dist" "$SERVER_DIR/dist"
# build backend
(cd "$SERVER_DIR" && go build -o app export.go import.go main.go)
# run server
"$SERVER_DIR/app" serve
else
echo "Usage: ./run.sh [dev|prod]"
exit 1
fi