# Access to fetch at 'http://localhost:8000/api' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

- **ID:** `python/fastapi-cors-preflight-blocked`
- **Domain:** python
- **Category:** network_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

FastAPI/Starlette app has no `CORSMiddleware`, or the middleware was added after routes / with wrong origins.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 0.100+ | active | — | — |

## Workarounds

1. **** (97% success)
   ```
   from fastapi.middleware.cors import CORSMiddleware
app.add_middleware(CORSMiddleware, allow_origins=['http://localhost:3000'], allow_credentials=True, allow_methods=['*'], allow_headers=['*'])
   ```
2. **** (93% success)
   ```
   allow_origins=os.environ['ALLOWED_ORIGINS'].split(',')
   ```

## Dead Ends

- **** — Not viable for end users; masks server config bug. (99% fail)
- **** — Preflight OPTIONS is handled before route; header missing on OPTIONS. (85% fail)
