Add new frontend - fix 16
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
"""Data service routes for API Gateway - Authentication handled by gateway middleware"""
|
||||
|
||||
from fastapi import APIRouter, Request, HTTPException
|
||||
from fastapi import APIRouter, Request, Response, HTTPException
|
||||
from fastapi.responses import StreamingResponse
|
||||
import httpx
|
||||
import logging
|
||||
@@ -10,23 +10,37 @@ from app.core.config import settings
|
||||
logger = logging.getLogger(__name__)
|
||||
router = APIRouter()
|
||||
|
||||
@router.api_route("/sales/{path:path}", methods=["GET", "POST", "PUT", "DELETE"])
|
||||
@router.api_route("/sales/{path:path}", methods=["GET", "POST", "PUT", "DELETE", "OPTIONS"])
|
||||
async def proxy_sales(request: Request, path: str):
|
||||
"""Proxy sales data requests to data service"""
|
||||
return await _proxy_request(request, f"/api/v1/sales/{path}")
|
||||
|
||||
@router.api_route("/weather/{path:path}", methods=["GET", "POST"])
|
||||
@router.api_route("/weather/{path:path}", methods=["GET", "POST", "OPTIONS"])
|
||||
async def proxy_weather(request: Request, path: str):
|
||||
"""Proxy weather requests to data service"""
|
||||
return await _proxy_request(request, f"/api/v1/weather/{path}")
|
||||
|
||||
@router.api_route("/traffic/{path:path}", methods=["GET", "POST"])
|
||||
@router.api_route("/traffic/{path:path}", methods=["GET", "POST", "OPTIONS"])
|
||||
async def proxy_traffic(request: Request, path: str):
|
||||
"""Proxy traffic requests to data service"""
|
||||
return await _proxy_request(request, f"/api/v1/traffic/{path}")
|
||||
|
||||
async def _proxy_request(request: Request, target_path: str):
|
||||
"""Proxy request to data 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.DATA_SERVICE_URL}{target_path}"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user