Skip to content
Snippets Groups Projects
Commit 320c9f0c authored by Neda Moeini's avatar Neda Moeini
Browse files

Restructure FAST API app and load configuration into app

parent 7f35eef1
No related branches found
No related tags found
1 merge request!1Feature/get graph data from gap
"""Initializes the FastAPI application."""
import os
"""Create a FastAPI application for the mapping provider."""
from fastapi import FastAPI
from mapping_provider import config
from mapping_provider.api.common import router as version_router
from mapping_provider.api.network_graph import router as graph_router
def create_app() -> FastAPI:
"""Create a FastAPI application."""
......@@ -14,9 +12,11 @@ def create_app() -> FastAPI:
description="Mapping provider endpoints for GÉANT maps",
)
config_file = os.environ.get("CONFIG_FILE_NAME", "config.json")
with config_file.open() as f:
app.state.config = config.load(f)
# Force configuration to be loaded at startup to avoid issues with missing config
from mapping_provider.dependencies import load_config
_ = load_config()
app.include_router(version_router)
return app
app.include_router(graph_router)
return app
\ No newline at end of file
"""FastAPI project dependencies."""
import os
from functools import lru_cache
from typing import Annotated
from fastapi import Depends
from mapping_provider import config
@lru_cache()
def load_config() -> dict:
"""Load and cache the application configuration."""
config_file = os.environ.get("CONFIG_FILE_NAME", "config.json")
with open(config_file) as f:
return config.load(f)
# Dependency for injecting config into routes/services
config_dep = Annotated[dict, Depends(load_config)]
\ No newline at end of file
"""The main module that runs the application."""
from mapping_provider import create_app
app = create_app()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment