FastAPI 0.138–0.141 adds app.frontend() to fix silent SPA routing conflicts
FastAPI versions 0.138.0 through 0.141.1, released between June 20 and July 29 this year, introduced a new app.frontend() method to simplify serving single-page applications alongside API routes. Previously, developers had to either mount StaticFiles at '/' or write a manual catch-all route, both of which could silently intercept API calls if declared in the wrong order. The new method stores frontend routes internally as low-priority entries, ensuring they are only evaluated after all standard API routes have been checked, regardless of where app.frontend() appears in the code. It also inspects the HTTP Accept header before falling back to index.html, returning a proper 404 for non-browser requests to missing assets instead of silently serving the SPA shell. This makes SPA serving in FastAPI a routing guarantee rather than a convention dependent on file order.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.


Discussion (0)
Log in to join the discussion and vote.
Log in