"""
passenger_wsgi.py
-------------------
Entry point cPanel's "Setup Python App" (Phusion Passenger) looks for.

Passenger on cPanel speaks WSGI, but FastAPI/uvicorn are ASGI. This file
wraps the ASGI app with a2wsgi's WSGIMiddleware so Passenger can serve it
without needing its own uvicorn process (which cPanel's Passenger setup
does not support running directly).

Nothing to edit here. Configuration lives in backend/.env (copy from
backend/.env.example) and in the cPanel "Setup Python App" screen.
"""

import sys
import os

BASE_DIR = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, BASE_DIR)

# Load backend/.env into the process environment before anything in
# backend/config.py reads os.getenv(...).
try:
    from dotenv import load_dotenv
    load_dotenv(os.path.join(BASE_DIR, "backend", ".env"))
except ImportError:
    pass  # python-dotenv not installed; fall back to real env vars set in cPanel

from a2wsgi import ASGIMiddleware
from backend.main import app as fastapi_app

application = ASGIMiddleware(fastapi_app)
