REFACTOR API gateway fix 5
This commit is contained in:
@@ -67,10 +67,21 @@ async def startup_event():
|
||||
logger.info("Starting API Gateway")
|
||||
|
||||
# Start metrics server
|
||||
metrics_collector.start_metrics_server(8080)
|
||||
metrics_collector.register_counter(
|
||||
"gateway_auth_requests_total",
|
||||
"Total authentication requests through gateway"
|
||||
)
|
||||
metrics_collector.register_counter(
|
||||
"gateway_auth_responses_total",
|
||||
"Total authentication responses through gateway"
|
||||
)
|
||||
metrics_collector.register_histogram(
|
||||
"gateway_request_duration_seconds",
|
||||
"Gateway request duration"
|
||||
)
|
||||
|
||||
# Initialize service discovery
|
||||
# await service_discovery.initialize()
|
||||
|
||||
metrics_collector.start_metrics_server(8080)
|
||||
|
||||
logger.info("API Gateway started successfully")
|
||||
|
||||
|
||||
@@ -42,10 +42,20 @@ async def get_tenant_members(request: Request, tenant_id: str = Path(...)):
|
||||
# TENANT-SCOPED DATA SERVICE ENDPOINTS
|
||||
# ================================================================
|
||||
|
||||
@router.api_route("/{tenant_id}/sales/{path:path}", methods=["GET", "POST", "PUT", "DELETE", "OPTIONS"])
|
||||
async def proxy_tenant_sales(request: Request, tenant_id: str = Path(...), path: str = ""):
|
||||
"""Proxy tenant sales requests to data service"""
|
||||
target_path = f"/api/v1/tenants/{tenant_id}/sales/{path}".rstrip("/")
|
||||
@router.api_route("/{tenant_id}/sales{path:path}", methods=["GET", "POST", "PUT", "DELETE", "OPTIONS"])
|
||||
async def proxy_all_tenant_sales_alternative(request: Request, tenant_id: str = Path(...), path: str = ""):
|
||||
"""Proxy all tenant sales requests - handles both base and sub-paths"""
|
||||
base_path = f"/api/v1/tenants/{tenant_id}/sales"
|
||||
|
||||
# If path is empty or just "/", use base path
|
||||
if not path or path == "/" or path == "":
|
||||
target_path = base_path
|
||||
else:
|
||||
# Ensure path starts with "/"
|
||||
if not path.startswith("/"):
|
||||
path = "/" + path
|
||||
target_path = base_path + path
|
||||
|
||||
return await _proxy_to_data_service(request, target_path)
|
||||
|
||||
@router.api_route("/{tenant_id}/weather/{path:path}", methods=["GET", "POST", "OPTIONS"])
|
||||
|
||||
Reference in New Issue
Block a user