import os, time, requests # Wait a bit for uvicorn to become available port = int(os.getenv("PORT", "7860")) base = f"http://127.0.0.1:{port}" for _ in range(60): try: r = requests.get(f"{base}/healthz", timeout=1) if r.status_code == 200: break except Exception: pass time.sleep(1) # Ensure DB created by hitting a simple endpoint (lazy create_all on import) try: requests.get(f"{base}/healthz", timeout=3) except Exception as e: print("init_db: healthz failed:", e) # Create admin if envs are present email = os.getenv("ADMIN_EMAIL") password = os.getenv("ADMIN_PASSWORD") if email and password: try: resp = requests.post(f"{base}/auth/bootstrap_admin", json={ "email": email, "password": password }, timeout=5) print("bootstrap_admin:", resp.status_code, resp.text[:500]) except Exception as e: print("bootstrap_admin failed:", e)