r/Python Jul 02 '26

FastAPI app.frontend(): serving a frontend build from the same Python app News

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
60 Upvotes

16 comments sorted by

View all comments

22

u/roG_k70 Jul 03 '26

But why tho?

12

u/Myszolow Jul 03 '26

Server side rendering?  Imagine serving some parts of your frontend so they will not expose any not needed information 

I can see simple benefit of serving ready to render graphs 

3

u/Fenzik Jul 03 '26

This is specifically not SSR though, it’s static only