Menu

FastAPI frontends and static files served from the CDN - Vercel
📰

FastAPI frontends and static files served from the CDN - Vercel

Vercel News·Daniel Park·5 days ago
#G228hSLy
#vercel#static#fastapi#staticfiles#function
Reading 0:00
15s threshold

FastAPI frontends and static files, served with app.frontend() or StaticFiles , are now promoted to the Vercel CDN at build time. Requests for those paths are served directly from the CDN, without invoking your Vercel Function.

app = FastAPI ( )

app . frontend ( "/" , directory = "dist" )

app . mount ( "/assets" , StaticFiles ( directory = "assets" ) , name = "assets" )

Frontend and StaticFiles, both promoted to the CDN.

FastAPI evaluates routes in declaration order. A route declared before a StaticFiles mount takes priority over any CDN file at that path. This precedence is preserved.

@app . get ( "/static/manifest.json" ) # served by your Vercel Function

def manifest ( ) : . . .

app . mount ( "/static" , StaticFiles ( directory = "static" ) , name = "static" )

A route that takes precedence over StaticFiles.

Promoted source directories remain in the function bundle so the app can read from them at runtime.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.