Skip to content

Commit 190f6e2

Browse files
authored
📝 Add Frontend instructions to Agent Library Skill (#15805)
1 parent 17945e5 commit 190f6e2

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

‎fastapi/.agents/skills/fastapi/SKILL.md‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,32 @@ There could be exceptions, but try to follow this convention.
288288

289289
Apply shared dependencies at the router level via `dependencies=[Depends(...)]`.
290290

291+
## Serve Frontend Apps
292+
293+
Use `app.frontend()` to serve a built static frontend app, for example a directory generated by Vite, Astro, Angular, Svelte, Vue, or a similar tool.
294+
295+
```python
296+
from fastapi import FastAPI
297+
298+
app = FastAPI()
299+
300+
app.frontend("/", directory="dist")
301+
```
302+
303+
Use `router.frontend()` when the frontend belongs to an `APIRouter`; normal router prefix behavior applies when the router is included.
304+
305+
```python
306+
from fastapi import APIRouter, FastAPI
307+
308+
app = FastAPI()
309+
router = APIRouter(prefix="/admin")
310+
311+
router.frontend("/", directory="admin-dist")
312+
app.include_router(router)
313+
```
314+
315+
`app.frontend()` and `router.frontend()` are low-priority routes: regular API routes are matched first, then frontend files and client-side routing fallbacks. Use this for single-page apps and built frontend assets instead of mounting `StaticFiles` manually.
316+
291317
## Dependency Injection
292318

293319
See [the dependency injection reference](references/dependencies.md) for detailed patterns including `yield` with `scope`, and class dependencies.

0 commit comments

Comments
 (0)