fix: resolve CORS middleware error causing backend restart
Some checks failed
CI/CD - Build & Test / Backend Tests (push) Has been cancelled
CI/CD - Build & Test / Frontend Tests (push) Has been cancelled
CI/CD - Build & Test / Security Scans (push) Has been cancelled
CI/CD - Build & Test / Docker Build Test (push) Has been cancelled
CI/CD - Build & Test / Terraform Validate (push) Has been cancelled
Deploy to Production / Build & Test (push) Has been cancelled
Deploy to Production / Security Scan (push) Has been cancelled
Deploy to Production / Build Docker Images (push) Has been cancelled
Deploy to Production / Deploy to Staging (push) Has been cancelled
Deploy to Production / E2E Tests (push) Has been cancelled
Deploy to Production / Deploy to Production (push) Has been cancelled
E2E Tests / Run E2E Tests (push) Has been cancelled
E2E Tests / Visual Regression Tests (push) Has been cancelled
E2E Tests / Smoke Tests (push) Has been cancelled
Some checks failed
CI/CD - Build & Test / Backend Tests (push) Has been cancelled
CI/CD - Build & Test / Frontend Tests (push) Has been cancelled
CI/CD - Build & Test / Security Scans (push) Has been cancelled
CI/CD - Build & Test / Docker Build Test (push) Has been cancelled
CI/CD - Build & Test / Terraform Validate (push) Has been cancelled
Deploy to Production / Build & Test (push) Has been cancelled
Deploy to Production / Security Scan (push) Has been cancelled
Deploy to Production / Build Docker Images (push) Has been cancelled
Deploy to Production / Deploy to Staging (push) Has been cancelled
Deploy to Production / E2E Tests (push) Has been cancelled
Deploy to Production / Deploy to Production (push) Has been cancelled
E2E Tests / Run E2E Tests (push) Has been cancelled
E2E Tests / Visual Regression Tests (push) Has been cancelled
E2E Tests / Smoke Tests (push) Has been cancelled
The issue was duplicate CORS middleware configuration: - CORS was configured in main.py (correctly) - CORS was also configured in security_headers.py (incorrectly) The security_headers.py version was trying to instantiate CORSMiddleware directly without the 'app' argument, causing: TypeError: CORSMiddleware.__init__() missing 1 required positional argument: 'app' Fixed by: 1. Removed CORS middleware from setup_security_middleware() 2. Updated config.py to include http://localhost:8888 in CORS origins 3. Kept CORS configuration only in main.py Backend now starts successfully and responds to health checks.
This commit is contained in:
@@ -44,8 +44,8 @@ class Settings(BaseSettings):
|
|||||||
|
|
||||||
# Security
|
# Security
|
||||||
bcrypt_rounds: int = 12
|
bcrypt_rounds: int = 12
|
||||||
cors_allowed_origins: List[str] = ["http://localhost:3000", "http://localhost:5173"]
|
cors_allowed_origins: List[str] = ["http://localhost:3000", "http://localhost:5173", "http://localhost:8888"]
|
||||||
cors_allowed_origins_production: List[str] = []
|
cors_allowed_origins_production: List[str] = ["http://localhost:8888"]
|
||||||
|
|
||||||
# Audit Logging
|
# Audit Logging
|
||||||
audit_logging_enabled: bool = True
|
audit_logging_enabled: bool = True
|
||||||
|
|||||||
@@ -245,10 +245,7 @@ def setup_security_middleware(app):
|
|||||||
Args:
|
Args:
|
||||||
app: FastAPI application instance
|
app: FastAPI application instance
|
||||||
"""
|
"""
|
||||||
# Add CORS middleware
|
# Note: CORS middleware is configured in main.py
|
||||||
cors_middleware = CORSSecurityMiddleware.get_middleware()
|
|
||||||
app.add_middleware(type(cors_middleware), **cors_middleware.__dict__)
|
|
||||||
|
|
||||||
# Add security headers middleware
|
# Add security headers middleware
|
||||||
app.add_middleware(SecurityHeadersMiddleware)
|
app.add_middleware(SecurityHeadersMiddleware)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user