-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev.sh
More file actions
executable file
·200 lines (165 loc) · 4.94 KB
/
Copy pathdev.sh
File metadata and controls
executable file
·200 lines (165 loc) · 4.94 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/bin/bash
# INAMSOS Simple Development Script
# Runs both backend and frontend without Docker
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# PID file locations
BACKEND_PID_FILE=".backend.pid"
FRONTEND_PID_FILE=".frontend.pid"
# Print colored output
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Cleanup function
cleanup() {
print_status "Stopping all services..."
# Kill backend process
if [ -f "$BACKEND_PID_FILE" ]; then
BACKEND_PID=$(cat "$BACKEND_PID_FILE")
if kill -0 "$BACKEND_PID" 2>/dev/null; then
kill "$BACKEND_PID" 2>/dev/null || true
print_success "Backend stopped"
fi
rm -f "$BACKEND_PID_FILE"
fi
# Kill frontend process
if [ -f "$FRONTEND_PID_FILE" ]; then
FRONTEND_PID=$(cat "$FRONTEND_PID_FILE")
if kill -0 "$FRONTEND_PID" 2>/dev/null; then
kill "$FRONTEND_PID" 2>/dev/null || true
print_success "Frontend stopped"
fi
rm -f "$FRONTEND_PID_FILE"
fi
print_success "All services stopped"
exit 0
}
# Set trap for cleanup
trap cleanup INT TERM
# Check if we're in the project root
if [ ! -d "backend" ] || [ ! -d "frontend" ]; then
print_error "Please run this script from the project root directory"
exit 1
fi
echo ""
echo "🏥 INAMSOS Development Environment"
echo "=================================="
echo ""
# Check if Bun is installed
if ! command -v bun &> /dev/null; then
print_error "Bun is not installed. Please install Bun first: https://bun.sh"
exit 1
fi
# Kill any processes on required ports
print_status "Cleaning up ports..."
BACKEND_PORT=3002
FRONTEND_PORT=3000
# Kill all dev processes that might be running
print_status "Stopping any existing dev processes..."
pkill -f "bun src/main.ts" 2>/dev/null || true
pkill -f "next dev" 2>/dev/null || true
sleep 2
# Kill processes on specific ports
for port in 3000 3001 3002 3003; do
if lsof -ti:$port > /dev/null 2>&1; then
print_warning "Port $port is in use, killing process..."
lsof -ti:$port | xargs kill -9 2>/dev/null || true
fi
done
sleep 1
print_success "All ports cleaned up"
# Start Backend
print_status "Starting backend server (Bun)..."
cd backend
# Check if .env.local exists
if [ ! -f ".env.local" ]; then
print_warning ".env.local not found, using .env"
fi
# Start backend in background, redirect output to log file
bun src/main.ts > ../backend.log 2>&1 &
BACKEND_PID=$!
echo $BACKEND_PID > "../$BACKEND_PID_FILE"
cd ..
print_success "Backend started (PID: $BACKEND_PID)"
# Wait for backend to bind to port
print_status "Waiting for backend to be ready..."
for i in {1..30}; do
if lsof -ti:3002 > /dev/null 2>&1; then
print_success "Backend is listening on port 3002"
break
fi
if ! kill -0 "$BACKEND_PID" 2>/dev/null; then
print_error "Backend failed to start. Check backend.log for errors."
tail -30 backend.log
exit 1
fi
sleep 1
done
if ! lsof -ti:3002 > /dev/null 2>&1; then
print_error "Backend failed to bind to port 3002. Check backend.log for errors."
tail -30 backend.log
exit 1
fi
# Start Frontend
print_status "Starting frontend server..."
cd frontend
# Check if .env.local exists
if [ ! -f ".env.local" ]; then
print_warning ".env.local not found, creating from .env"
fi
# Check if node_modules exists
if [ ! -d "node_modules" ]; then
print_status "Installing frontend dependencies..."
npm install
fi
# Start frontend in background, redirect output to log file
npm run dev > ../frontend.log 2>&1 &
FRONTEND_PID=$!
echo $FRONTEND_PID > "../$FRONTEND_PID_FILE"
cd ..
print_success "Frontend started (PID: $FRONTEND_PID)"
# Wait for services to be ready
print_status "Waiting for services to be ready..."
sleep 5
# Display access information
echo ""
echo "=================================================================="
echo "🏥 INAMSOS Development Environment Ready!"
echo "=================================================================="
echo ""
echo "📊 Application URLs:"
echo " Frontend: http://localhost:3000"
echo " Backend API: http://localhost:3002/api/v1"
echo " API Docs: http://localhost:3002/api/docs"
echo ""
echo "🗄️ Database:"
echo " Remote PostgreSQL (107.155.75.50:5389)"
echo ""
echo "📝 Logs:"
echo " Backend: tail -f backend.log"
echo " Frontend: tail -f frontend.log"
echo ""
echo "🛠️ Commands:"
echo " Stop: Press Ctrl+C"
echo " Restart: Stop and run ./dev.sh again"
echo ""
echo "=================================================================="
print_success "Development environment is running!"
print_status "Press Ctrl+C to stop all services"
echo ""
# Follow logs
# tail -f backend.log frontend.log