63 lines
1.9 KiB
Python
63 lines
1.9 KiB
Python
from fastapi import APIRouter, Response, Depends
|
|
from fastapi.responses import FileResponse
|
|
from fastapi.staticfiles import StaticFiles
|
|
import os
|
|
import logging
|
|
from pathlib import Path as FilePath
|
|
from typing import Dict, Any
|
|
|
|
from modules.shared.configuration import APP_CONFIG
|
|
from modules.security.auth import limiter, getCurrentUser
|
|
|
|
router = APIRouter(
|
|
prefix="",
|
|
tags=["General"],
|
|
responses={404: {"description": "Not found"}}
|
|
)
|
|
|
|
# Static folder setup - using absolute path from app root
|
|
baseDir = FilePath(__file__).parent.parent.parent # Go up to gateway root
|
|
staticFolder = baseDir / "static"
|
|
os.makedirs(staticFolder, exist_ok=True)
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
router = APIRouter(
|
|
prefix="",
|
|
tags=["Administration"],
|
|
responses={404: {"description": "Not found"}}
|
|
)
|
|
|
|
# Mount static files
|
|
router.mount("/static", StaticFiles(directory=str(staticFolder), html=True), name="static")
|
|
|
|
@router.get("/")
|
|
@limiter.limit("30/minute")
|
|
async def root():
|
|
"""API status endpoint"""
|
|
return {
|
|
"status": "online",
|
|
"message": "Data Platform API is active",
|
|
"allowedOrigins": f"Allowed origins are {APP_CONFIG.get('APP_ALLOWED_ORIGINS')}"
|
|
}
|
|
|
|
@router.get("/api/environment")
|
|
@limiter.limit("30/minute")
|
|
async def get_environment(currentUser: Dict[str, Any] = Depends(getCurrentUser)):
|
|
"""Get environment configuration for frontend"""
|
|
return {
|
|
"apiBaseUrl": APP_CONFIG.get("APP_API_URL", ""),
|
|
"environment": APP_CONFIG.get("APP_ENV", "development"),
|
|
"instanceLabel": APP_CONFIG.get("APP_ENV_LABEL", "Development"),
|
|
# Add other environment variables the frontend might need
|
|
}
|
|
|
|
@router.options("/{fullPath:path}")
|
|
@limiter.limit("60/minute")
|
|
async def options_route(fullPath: str):
|
|
return Response(status_code=200)
|
|
|
|
@router.get("/favicon.ico")
|
|
@limiter.limit("30/minute")
|
|
async def favicon():
|
|
return FileResponse(str(staticFolder / "favicon.ico"), media_type="image/x-icon")
|