Frontend on localhost:3000 gets errors calling FastAPI on localhost:8000. Name and fix?
This tests whether different ports mean different origins, causing CORS errors. A strong answer names CORS, notes ports are distinct origins, and outlines using CORSMiddleware with allow_origins.
This tests whether you understand that origin is defined by protocol plus domain plus port, so localhost:3000 and localhost:8000 are different origins and browsers block cross-origin requests by default. A strong answer names the CORS error, explains the origin mismatch, and walks through importing and mounting CORSMiddleware with an explicit allow_origins list including the frontend origin. A red flag is recommending browser plugins, CLI flags, or wildcarding allow_origins to star in production without understanding security implications.
Read the original → fastapi.tiangolo.com
- #fastapi
- #cors
- #backend
- #web
- #security
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.