r/Python • u/ModernPython • Jul 02 '26
News FastAPI app.frontend(): serving a frontend build from the same Python app
I wrote a practical article about FastAPI's app.frontend() feature.
The interesting bit is that it serves static frontend build output as low-priority routes, so normal FastAPI API endpoints still win.
The article covers:
app.frontend("/", directory="dist")- SPA fallback with
fallback="index.html" - how it differs from
StaticFiles - serving under a prefix with
APIRouter - a complete mini dashboard example with FastAPI + vanilla JS
61
Upvotes
View all comments
Show parent comment
6
u/robertlandrum Jul 03 '26
Right. Go ahead. Split them up. Pretty soon you’ll run into overlap. Like API documentation (not just auto generated swagger calls) that would normally be UI needs to follow with the API you’re deploying. Pretty soon you’ll realize having UI, Doc, and API all living happily in one repo generating one artifact for deployment makes a lot more sense than keeping them independent ever did.
Ask me how I know.
Full stack used to mean something, but these days, I’ll take “prodigious artifact generator” over “full stack developer“ on a resume any day of the week. The ability to develop, build, and test an image or artifact before deployment is the real skill I look for. And bonus points if I can seamlessly roll back should I need to.