Spaces:
Build error
Build error
| # Set paths | |
| BACKEND_DIR="/workspaces/arf-api" | |
| FRONTEND_DIR="/workspaces/arf-frontend" | |
| VENV_ACTIVATE="$BACKEND_DIR/venv/bin/activate" | |
| CLOUDFLARED=$(which cloudflared 2>/dev/null || echo "/usr/local/bin/cloudflared") | |
| # Kill any existing processes | |
| echo "π Stopping existing uvicorn and cloudflared..." | |
| pkill -f uvicorn | |
| pkill -f cloudflared | |
| sleep 2 | |
| # Start uvicorn | |
| echo "π Starting uvicorn..." | |
| cd "$BACKEND_DIR" | |
| source "$VENV_ACTIVATE" | |
| uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload & | |
| sleep 3 | |
| # Verify uvicorn is running | |
| if ! curl -s http://localhost:8000/health >/dev/null; then | |
| echo "β uvicorn failed to start. Exiting." | |
| exit 1 | |
| fi | |
| echo "β uvicorn is running." | |
| # Start cloudflared and capture URL | |
| echo "π Starting cloudflared tunnel..." | |
| TEMP_FILE=$(mktemp) | |
| $CLOUDFLARED tunnel --url http://localhost:8000 2>&1 | tee "$TEMP_FILE" & | |
| # Wait for URL to appear | |
| echo "β³ Waiting for tunnel URL..." | |
| URL="" | |
| for i in {1..30}; do | |
| URL=$(grep -oP 'https://[a-z0-9-]+\.trycloudflare\.com' "$TEMP_FILE" | head -1) | |
| if [ -n "$URL" ]; then | |
| break | |
| fi | |
| sleep 1 | |
| done | |
| if [ -z "$URL" ]; then | |
| echo "β Failed to get tunnel URL." | |
| exit 1 | |
| fi | |
| echo "β Tunnel URL: $URL" | |
| # Save URL for monitoring (used by monitor.sh) | |
| echo "$URL" > /workspaces/arf-api/current_url.txt | |
| # Update Vercel environment variable | |
| echo "π§ Updating Vercel environment variable..." | |
| cd "$FRONTEND_DIR" | |
| if command -v vercel &>/dev/null; then | |
| vercel env rm NEXT_PUBLIC_API_URL production -y | |
| echo "$URL" | vercel env add NEXT_PUBLIC_API_URL production | |
| echo "π Redeploying frontend..." | |
| vercel --prod | |
| else | |
| echo "β οΈ Vercel CLI not installed. Please install it with: npm i -g vercel" | |
| echo "Then manually update the env var to: $URL" | |
| fi | |
| echo "π All done! Your new URL is: $URL" | |
| echo "Frontend will be updated shortly. Check https://arf-frontend-sandy.vercel.app" |