diff --git a/projects/fal/src/fal/app.py b/projects/fal/src/fal/app.py index f3c2676d..1a3d40b3 100644 --- a/projects/fal/src/fal/app.py +++ b/projects/fal/src/fal/app.py @@ -72,6 +72,10 @@ def __init__(self, *, _allow_init: bool = False): def setup(self): """Setup the application before serving.""" + def provide_hints(self) -> list[str]: + """Provide hints for routing the application.""" + return [] + def serve(self) -> None: import uvicorn @@ -92,6 +96,16 @@ async def lifespan(app: FastAPI): _app = FastAPI(lifespan=lifespan) + @_app.middleware("http") + async def provide_hints(request, call_next): + response = await call_next(request) + try: + response.headers["X-Fal-Runner-Hints"] = ",".join(self.provide_hints()) + except Exception as exc: + logger.warning("Failed to provide hints: %s", exc) + + return response + _app.add_middleware( CORSMiddleware, allow_credentials=True,