Add new frontend - fix 16
This commit is contained in:
@@ -12,18 +12,32 @@ from app.core.config import settings
|
||||
logger = logging.getLogger(__name__)
|
||||
router = APIRouter()
|
||||
|
||||
@router.api_route("/forecasts/{path:path}", methods=["GET", "POST", "PUT", "DELETE"])
|
||||
@router.api_route("/forecasts/{path:path}", methods=["GET", "POST", "PUT", "DELETE", "OPTIONS"])
|
||||
async def proxy_forecasts(request: Request, path: str):
|
||||
"""Proxy forecast requests to forecasting service"""
|
||||
return await _proxy_request(request, f"/api/v1/forecasts/{path}")
|
||||
|
||||
@router.api_route("/predictions/{path:path}", methods=["GET", "POST"])
|
||||
@router.api_route("/predictions/{path:path}", methods=["GET", "POST", "OPTIONS"])
|
||||
async def proxy_predictions(request: Request, path: str):
|
||||
"""Proxy prediction requests to forecasting service"""
|
||||
return await _proxy_request(request, f"/api/v1/predictions/{path}")
|
||||
|
||||
async def _proxy_request(request: Request, target_path: str):
|
||||
"""Proxy request to forecasting service with user context"""
|
||||
|
||||
# Handle OPTIONS requests directly for CORS
|
||||
if request.method == "OPTIONS":
|
||||
return Response(
|
||||
status_code=200,
|
||||
headers={
|
||||
"Access-Control-Allow-Origin": settings.CORS_ORIGINS_LIST,
|
||||
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
|
||||
"Access-Control-Allow-Headers": "Content-Type, Authorization, X-Tenant-ID",
|
||||
"Access-Control-Allow-Credentials": "true",
|
||||
"Access-Control-Max-Age": "86400" # Cache preflight for 24 hours
|
||||
}
|
||||
)
|
||||
|
||||
try:
|
||||
url = f"{settings.FORECASTING_SERVICE_URL}{target_path}"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user