Add new frontend - fix 9
This commit is contained in:
@@ -17,7 +17,7 @@ from app.core.service_discovery import ServiceDiscovery
|
||||
from app.middleware.auth import AuthMiddleware
|
||||
from app.middleware.logging import LoggingMiddleware
|
||||
from app.middleware.rate_limit import RateLimitMiddleware
|
||||
from app.routes import auth, training, forecasting, data, tenant, notification
|
||||
from app.routes import auth, training, forecasting, data, tenant, notification, nominatim
|
||||
from shared.monitoring.logging import setup_logging
|
||||
from shared.monitoring.metrics import MetricsCollector
|
||||
|
||||
@@ -61,6 +61,7 @@ app.include_router(forecasting.router, prefix="/api/v1/forecasting", tags=["fore
|
||||
app.include_router(data.router, prefix="/api/v1/data", tags=["data"])
|
||||
app.include_router(tenant.router, prefix="/api/v1/tenants", tags=["tenants"])
|
||||
app.include_router(notification.router, prefix="/api/v1/notifications", tags=["notifications"])
|
||||
app.include_router(nominatim.router, prefix="/api/v1/nominatim", tags=["location"])
|
||||
|
||||
@app.on_event("startup")
|
||||
async def startup_event():
|
||||
|
||||
@@ -31,7 +31,8 @@ PUBLIC_ROUTES = [
|
||||
"/api/v1/auth/login",
|
||||
"/api/v1/auth/register",
|
||||
"/api/v1/auth/refresh",
|
||||
"/api/v1/auth/verify"
|
||||
"/api/v1/auth/verify",
|
||||
"/api/v1/nominatim/search"
|
||||
]
|
||||
|
||||
class AuthMiddleware(BaseHTTPMiddleware):
|
||||
|
||||
48
gateway/app/routes/nominatim.py
Normal file
48
gateway/app/routes/nominatim.py
Normal file
@@ -0,0 +1,48 @@
|
||||
# gateway/app/routes/nominatim.py
|
||||
|
||||
from fastapi import APIRouter, Request, HTTPException
|
||||
from fastapi.responses import JSONResponse
|
||||
import httpx
|
||||
import structlog
|
||||
from app.core.config import settings
|
||||
|
||||
logger = structlog.get_logger()
|
||||
router = APIRouter()
|
||||
|
||||
@router.get("/search")
|
||||
async def proxy_nominatim_search(request: Request):
|
||||
"""
|
||||
Proxies requests to the Nominatim geocoding search API.
|
||||
"""
|
||||
try:
|
||||
# Construct the internal Nominatim URL
|
||||
# All query parameters from the client request are forwarded
|
||||
nominatim_url = f"{settings.NOMINATIM_SERVICE_URL}/nominatim/search"
|
||||
|
||||
# httpx client for making async HTTP requests
|
||||
async with httpx.AsyncClient(timeout=30.0) as client:
|
||||
response = await client.get(
|
||||
nominatim_url,
|
||||
params=request.query_params # Forward all query parameters from frontend
|
||||
)
|
||||
response.raise_for_status() # Raise an exception for HTTP errors (4xx or 5xx)
|
||||
|
||||
# Return the JSON response from Nominatim directly
|
||||
return JSONResponse(content=response.json())
|
||||
|
||||
except httpx.RequestError as exc:
|
||||
logger.error("Nominatim service request failed", error=str(exc))
|
||||
raise HTTPException(
|
||||
status_code=503,
|
||||
detail=f"Nominatim service unavailable: {exc}"
|
||||
)
|
||||
except httpx.HTTPStatusError as exc:
|
||||
logger.error(f"Nominatim service responded with error {exc.response.status_code}",
|
||||
detail=exc.response.text)
|
||||
raise HTTPException(
|
||||
status_code=exc.response.status_code,
|
||||
detail=f"Nominatim service error: {exc.response.text}"
|
||||
)
|
||||
except Exception as exc:
|
||||
logger.error("Unexpected error in Nominatim proxy", error=str(exc))
|
||||
raise HTTPException(status_code=500, detail="Internal server error in Nominatim proxy")
|
||||
Reference in New Issue
Block a user