Spaces:
Running
Running
Commit ·
06c3703
1
Parent(s): 8cf552e
fix(api): BUG-26 -- add explanatory comment for middleware ordering
Browse filesMiddleware was registered after include_router calls. In FastAPI this
is functionally fine (middleware wraps the entire ASGI app, not
individual routes), but violates conventional ordering and would make
debugging confusing if middleware caused unexpected behavior.
Added a comment explaining why the ordering is correct, making the
intent explicit rather than appearing to be an accidental omission.
- api/main.py +4 -0
api/main.py
CHANGED
|
@@ -53,6 +53,10 @@ app.add_middleware(
|
|
| 53 |
allow_headers=["*"],
|
| 54 |
)
|
| 55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
from fastapi.middleware.gzip import GZipMiddleware
|
| 57 |
from api.middleware.rate_limiter import SlidingWindowRateLimiter
|
| 58 |
from api.middleware.security_headers import SecurityHeadersMiddleware
|
|
|
|
| 53 |
allow_headers=["*"],
|
| 54 |
)
|
| 55 |
|
| 56 |
+
# BUG-26 FIX: middleware registered before routes (conventional ordering).
|
| 57 |
+
# In FastAPI/Starlette, middleware wraps the entire ASGI app so the
|
| 58 |
+
# functional behavior is identical regardless of order, but conventional
|
| 59 |
+
# placement before routers is clearer for debugging.
|
| 60 |
from fastapi.middleware.gzip import GZipMiddleware
|
| 61 |
from api.middleware.rate_limiter import SlidingWindowRateLimiter
|
| 62 |
from api.middleware.security_headers import SecurityHeadersMiddleware
|