CORS (Cross-Origin Resource Sharing) เป็นกลไกความปลอดภัยของเบราว์เซอร์ที่ควบคุมว่าเว็บเพจจาก origin หนึ่งจะสามารถเรียก API ของคุณที่อยู่คนละ origin ได้หรือไม่ FastAPI ตั้งค่าเรื่องนี้ด้วย CORSMiddleware ที่มีมาให้ในตัว คุณจะเจอ CORS เมื่อใดก็ตามที่ frontend บนคนละ domain/port เรียก API ของคุณ
ปัญหาที่ CORS เข้ามาจัดการ
A React app at http://localhost:3000 calling an API at http://localhost:8000 is
CROSS-ORIGIN (different port). The BROWSER blocks the response unless the API
sends CORS headers permitting that origin.
(origin = scheme + host + port)
