File size: 1,445 Bytes
b0798af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/bin/bash
set -e

echo "=== Starting Stillwave Container on Hugging Face Spaces ==="

# Check for Hugging Face Persistent Storage at /data
if [ -d "/data" ] && [ -w "/data" ]; then
  export DATA_DIR="/data"
  echo "Persistent storage detected at /data"
else
  export DATA_DIR="/app/backend/data"
  echo "Using container storage at /app/backend/data"
fi

mkdir -p "$DATA_DIR"

export PORT=5000
export HOST="127.0.0.1"
export NODE_ENV=production
export API_PROXY_TARGET="http://127.0.0.1:5000"

echo "Starting NestJS backend on http://127.0.0.1:5000..."
cd /app/backend
node dist/main.js &
BACKEND_PID=$!

echo "Waiting for backend API to be ready..."
READY=0
for i in $(seq 1 30); do
  if curl -s http://127.0.0.1:5000/api/v1/health | grep -q '"status":"ok"'; then
    READY=1
    echo "Backend is ready! (health check passed)"
    break
  fi
  sleep 1
done

if [ $READY -eq 0 ]; then
  echo "Backend health check timed out. Proceeding with frontend launch..."
fi

echo "Starting Next.js frontend on http://0.0.0.0:7860..."
cd /app/frontend

cleanup() {
  echo "Shutting down Stillwave..."
  kill -TERM "$BACKEND_PID" 2>/dev/null || true
  kill -TERM "$FRONTEND_PID" 2>/dev/null || true
  wait "$BACKEND_PID" 2>/dev/null || true
  wait "$FRONTEND_PID" 2>/dev/null || true
  exit 0
}

trap cleanup SIGTERM SIGINT

npx next start -p 7860 -H 0.0.0.0 &
FRONTEND_PID=$!

# Wait for either process to terminate
wait -n "$BACKEND_PID" "$FRONTEND_PID"