-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·111 lines (96 loc) · 2.95 KB
/
run.sh
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
#!/usr/bin/env bash
# Exit on error
set -e
# Function to log messages
log() {
echo "[$(date +'%Y-%m-%d %H:%M:%S')] $1"
}
# Function to check if a port is in use
check_port() {
local port=$1
if lsof -i :$port >/dev/null 2>&1; then
log "Error: Port $port is already in use"
return 1
fi
return 0
}
# Check required ports at startup
log "Checking port availability..."
required_ports=(3001 8001 8080)
for port in "${required_ports[@]}"; do
if ! check_port $port; then
log "Please free up port $port before running the application"
exit 1
fi
done
# Setup backend environment if it doesn't exist
cd backend
if [ ! -d "venv" ]; then
log "Creating Python virtual environment..."
python3 -m venv venv
source venv/bin/activate
log "Installing Python dependencies..."
pip install -r requirements.txt
else
source venv/bin/activate
fi
# Create required directories
log "Setting up required directories..."
cd src
mkdir -p api/mitmproxy
mkdir -p api/sessions
# Initialize mitmproxy certificates if they don't exist
if [ ! -f "api/mitmproxy/mitmproxy-ca.pem" ]; then
log "Initializing mitmproxy certificates..."
# Run mitmdump with minimal options to generate certs
mitmdump --set confdir=api/mitmproxy --set ssl_insecure=true --no-server &
MITM_PID=$!
sleep 2
kill $MITM_PID 2>/dev/null || true
if [ ! -f "api/mitmproxy/mitmproxy-ca.pem" ]; then
log "Error: Failed to generate mitmproxy certificates"
exit 1
fi
log "Certificates generated successfully"
fi
# Start the backend with debug output
log "Starting backend server..."
export PYTHONPATH=$PYTHONPATH:.
export FART_API_HOST=127.0.0.1
export FART_API_PORT=8001
export FART_UI_PORT=3001
export PYTHONUNBUFFERED=1
export FART_DEBUG_LEVEL=DEBUG
# Start backend with increased verbosity
log "Starting backend with debug logging..."
python -m api.main --log-level debug 2>&1 | tee backend.log &
BACKEND_PID=$!
# Start the frontend
log "Starting frontend..."
cd ../../frontend
# Install frontend dependencies if needed
if [ ! -d "node_modules" ]; then
log "Installing frontend dependencies..."
npm install 2>&1 | tee npm-install.log
log "Frontend dependencies installation completed"
fi
# Set environment variables for React build
export GENERATE_SOURCEMAP=true
export TSC_COMPILE_ON_ERROR=true
export BABEL_ENV=development
export NODE_ENV=development
# Reduce Babel logging verbosity
export DEBUG='!babel:*'
# Start frontend with filtered logging
log "Starting frontend with filtered logging..."
PORT=3001 BROWSER=none npm start 2>&1 | grep -v "babel" | tee frontend.log &
FRONTEND_PID=$!
log "Application is starting..."
log "Backend URL: http://127.0.0.1:8001"
log "Frontend URL: http://127.0.0.1:3001"
log "Log files:"
log "- Backend log: backend/src/backend.log"
log "- Frontend log: frontend/frontend.log"
log "- NPM install log: frontend/npm-install.log"
# Wait for both processes
wait $BACKEND_PID $FRONTEND_PID