Vercel's October 21 release brought routing middleware to Python, through the vercel-proxy package. It runs before your app and can route, redirect and rewrite request headers, and the example in the changelog redirects with an HTTP 308. Copy that example straight into a FastAPI project and you can ship two bugs in one commit: a redirect that browsers remember forever, and an auth check that lives in the wrong layer.
TL;DR
Routing middleware runs before your FastAPI app. FastAPI's own @app.middleware("http") runs inside it. They are different layers, so don't treat them as one stack.
308 means "moved for good, keep the method and body". Use it for URLs that really moved, and use 307 for anything temporary like a login gate.
Let routing middleware do coarse work (redirects, routing, cheap rejects).…