# fastapi.exceptions.HTTPException: 500 Internal Server Error: CORS error: Origin http://localhost:3000 is not allowed.

- **ID:** `python/fastapi-cors-origin-not-allowed`
- **Domain:** python
- **Category:** config_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

跨域请求来源未在 CORS 配置中允许。

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.x | active | — | — |

## Workarounds

1. **** (95% success)
   ```
   from fastapi.middleware.cors import CORSMiddleware\napp.add_middleware(CORSMiddleware, allow_origins=['http://localhost:3000'], allow_methods=['*'], allow_headers=['*'])
   ```
2. **** (90% success)
   ```
   allow_origin_regex='https?://localhost:3000'
   ```

## Dead Ends

- **** — 未处理预检请求，且配置繁琐。 (70% fail)
- **** — 当 allow_credentials=True 时，不能使用通配符。 (80% fail)
