Spaces:
Running
Running
File size: 1,189 Bytes
5d79ddf 55609dc b70c5b9 6d4d2c0 55609dc b70c5b9 5d79ddf 76a58d5 b70c5b9 76a58d5 b70c5b9 76a58d5 b8925b7 b70c5b9 b8925b7 55609dc b70c5b9 272bd90 | 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 | #!/bin/bash
set -euo pipefail
# Hugging Face Spaces exposes a single external port via $PORT (usually 7860).
# Keep internal ports fixed; nginx listens on $PORT and proxies to them.
API_PORT="8000"
export PORT="${PORT:-7860}"
# Start FastAPI on API_PORT
echo "Starting OpenEnv API server on port ${API_PORT}..."
uvicorn server.app:app --host 0.0.0.0 --port "${API_PORT}" &
# Start the Streamlit Dashboard (User UI) in the background with Proxy-friendly settings
echo "Starting Streamlit Dashboard on port 8501..."
streamlit run patchhawk/app/dashboard.py \
--server.port 8501 \
--server.address 0.0.0.0 \
--server.enableCORS false \
--server.enableXsrfProtection false \
--server.headless true \
--browser.gatherUsageStats false &
# Give services a moment to bind
echo "Waiting for services to initialize..."
sleep 5
# Start Nginx in foreground on PORT
echo "Starting Nginx reverse proxy on ${PORT}..."
envsubst '${PORT}' < /etc/nginx/nginx.conf > /tmp/nginx.conf
# Validate Nginx config
nginx -t -c /tmp/nginx.conf
if [ $? -ne 0 ]; then
echo "[ERROR] Nginx configuration validation failed!"
exit 1
fi
exec nginx -c /tmp/nginx.conf -g "daemon off;"
|