CORS(跨源资源共享)是一种浏览器安全机制,用于控制来自一个源的网页是否可以调用您的 API(位于不同源上)。FastAPI 使用内置的 CORSMiddleware 来配置它。当不同域/端口上的前端调用您的 API 时,您会遇到 CORS。
CORS 解决的问题
text
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)
