#!/bin/bash set -e SUBDOMAIN=${LT_SUBDOMAIN:-vercel} # Start g4f API server in background python -m g4f --port 7860 & G4F_PID=$! sleep 2 echo "Creating public tunnel..." # Try with the requested subdomain first if npx localtunnel --port 7860 --print-requests --subdomain "${SUBDOMAIN}"; then echo "Tunnel established: https://${SUBDOMAIN}.loca.lt" else echo "Subdomain '${SUBDOMAIN}' is taken or an error occurred. Falling back to random subdomain..." # Now let localtunnel generate a random subdomain (blocking call) npx localtunnel --port 7860 --print-requests fi # Cleanup when the tunnel exits kill $G4F_PID 2>/dev/null wait $G4F_PID 2>/dev/null