Skip to content

Commit

Permalink
feat: provide runner hints
Browse files Browse the repository at this point in the history
  • Loading branch information
isidentical committed Jan 27, 2024
1 parent 3f067db commit 5f52bd6
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions projects/fal/src/fal/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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,
Expand Down

0 comments on commit 5f52bd6

Please sign in to comment.