mirror of
https://github.com/sunrin-ana/2025-SSF.git
synced 2026-03-09 18:40:02 +00:00
21 lines
747 B
Python
21 lines
747 B
Python
import os
|
|
import traceback
|
|
from fastapi import APIRouter
|
|
from fastapi.logger import logger
|
|
|
|
|
|
router = APIRouter()
|
|
|
|
for router_file in os.listdir("Backend/router/endpoints"):
|
|
try:
|
|
if router_file.endswith(".py"):
|
|
module_name = "Backend.router.endpoints." + router_file[:-3]
|
|
module = __import__(module_name, fromlist=[""])
|
|
router_object = getattr(module, "router")
|
|
prefix = getattr(module, "prefix", router_file[:-3])
|
|
|
|
router.include_router(router_object, prefix="/api", tags=[router_file[:-3]])
|
|
print(f"Loaded router: /api/{prefix} - {router_file}")
|
|
|
|
except Exception as e:
|
|
logger.error(f"Error loading router {router_file}:\n{traceback.format_exc()}")
|