Repository navigation
Expand file tree
/
Copy pathstart_localwebapp.command
More file actions
108 lines (95 loc) · 3.49 KB
/
Copy pathstart_localwebapp.command
File metadata and controls
108 lines (95 loc) · 3.49 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
105
106
107
108
#!/bin/bash
set -e
# Change to script directory (for double-click execution)
cd "$(dirname "$0")"
echo ""
echo "========================================"
echo " NethAddress Local Development Setup"
echo "========================================"
echo ""
# Colours
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Colour
# Step 1: Check if .env exists
echo -e "${YELLOW}[1/5] Checking for .env file...${NC}"
if [ ! -f .env ]; then
cp .env.example .env
echo -e "${GREEN} Copied .env.example to .env${NC}"
else
echo -e "${GREEN} .env file already exists.${NC}"
fi
echo ""
# Step 2: Compile SCSS
echo -e "${YELLOW}[2/5] Compiling SCSS...${NC}"
if ! command -v sass &> /dev/null; then
echo -e "${YELLOW} Sass not found. Checking for npm...${NC}"
if ! command -v npm &> /dev/null; then
echo -e "${RED} ERROR: npm not found. Please install Node.js from https://nodejs.org/${NC}"
exit 1
fi
echo -e "${YELLOW} Installing sass globally via npm...${NC}"
npm install -g sass
fi
echo " Running: sass frontend/static/scss/main.scss frontend/static/css/styles.css"
sass frontend/static/scss/main.scss frontend/static/css/styles.css --style=expanded
echo -e "${GREEN} SCSS compiled successfully.${NC}"
echo ""
# Step 3: Run docker-compose
echo -e "${YELLOW}[3/5] Starting Docker services (PostgreSQL, Redis)...${NC}"
if ! docker info &> /dev/null; then
echo -e "${YELLOW} Docker is not running. Skipping Redis/PostgreSQL.${NC}"
DOCKER_AVAILABLE=0
else
docker-compose -f docker-compose.local.yml stop backend 2>/dev/null || true
docker-compose -f docker-compose.local.yml up -d db cache
echo -e "${GREEN} Docker services started in background.${NC}"
DOCKER_AVAILABLE=1
fi
echo ""
# Step 4: Start Backend Locally
echo -e "${YELLOW}[4/5] Starting Backend locally...${NC}"
export POSTGRES_DB=nethaddress_db
export POSTGRES_USER=nethaddress_user
export POSTGRES_PASSWORD=nethaddress_password
export DATABASE_URL=postgres://nethaddress_user:nethaddress_password@localhost:5432/nethaddress_db?sslmode=disable
export REDIS_URL=redis://localhost:6379
# Build backend if binary doesn't exist
if [ ! -f backend/backend ]; then
echo -e "${YELLOW} Building backend binary...${NC}"
cd backend && go build -o backend main.go && cd ..
fi
./backend/backend &
BACKEND_PID=$!
echo -e "${GREEN} Backend started (PID: $BACKEND_PID).${NC}"
echo ""
# Step 5: Start frontend server
echo -e "${YELLOW}[5/5] Starting frontend server...${NC}"
# Kill any process listening on port 3000
if lsof -Pi :3000 -sTCP:LISTEN -t >/dev/null 2>&1; then
echo -e "${YELLOW} Killing existing process on port 3000...${NC}"
lsof -Pi :3000 -sTCP:LISTEN -t | xargs kill -9 2>/dev/null || true
fi
cd frontend && python3 -m http.server 3000 &
FRONTEND_PID=$!
cd ..
echo -e "${GREEN} Frontend server started (PID: $FRONTEND_PID).${NC}"
echo ""
# Open browser
echo -e "${YELLOW}Opening http://localhost:3000 in your browser...${NC}"
sleep 2
open http://localhost:3000 &
echo ""
echo "========================================"
echo -e "${GREEN} NethAddress is now running!${NC}"
echo "========================================"
echo " Frontend: http://localhost:3000"
echo " Backend: http://localhost:8080"
echo ""
echo " Press Ctrl+C to stop all services."
echo "========================================"
echo ""
# Wait for user interrupt
trap "echo ''; echo 'Shutting down...'; kill $BACKEND_PID $FRONTEND_PID 2>/dev/null; exit 0" INT TERM
wait