Newer
Older
python_redirect / router.py
@Jason Poage Jason Poage on 24 Mar 822 bytes Debug
"""
FastAPI routing configuration.
Maps incoming HTTP requests to the FastAPIProxyRedirect class.
"""

from fastapi import FastAPI, Request, Response

from logger import debug_log

from fast_api import FastAPIProxyRedirect

app = FastAPI()


@app.get("/authelia-auth")
async def auth_passthrough():
    """
    Explicitly handle authelia-auth if Nginx accidentally routes here.
    Returning a 401 triggers the redirect logic in Nginx properly.
    """
    # Redirect  https://auth.jasonpoage.com/?rd=$scheme://$host$request_uri;
    return Response(status_code=200)


@app.get("/{full_path:path}")
async def proxy_handler(request: Request):
    """
    Catch-all route that passes the request to the proxy logic and returns the response.
    """
    proxy = FastAPIProxyRedirect(request)

    return proxy.get_response()