From 16c79aca39baac307cdb0bc7ba414a6aa531534e Mon Sep 17 00:00:00 2001 From: Scott Idem Date: Thu, 15 Jan 2026 16:45:10 -0500 Subject: [PATCH] Cleanup: Finalize modularization of app/main.py --- app/main.py | 52 ++++------------------------------------------------ 1 file changed, 4 insertions(+), 48 deletions(-) diff --git a/app/main.py b/app/main.py index fd4e333..c4543d9 100644 --- a/app/main.py +++ b/app/main.py @@ -15,18 +15,11 @@ from . import config import logging import app.log -# Baby step: Import the new registry module -from app.routers.registry import setup_routers - # Import middleware with alias to avoid shadowing 'app' FastAPI instance from app.middleware import add_process_time_header as process_time_middleware -# Import the routers here first: -from app.routers import ae_obj, aether_cfg, api_crud, api_crud_v2, api_crud_v3, api, importing, sql, account, activity_log, address, archive, archive_content, contact, data_store, event, event_abstract, event_badge, event_badge_importing, event_badge_template, event_device, event_exhibit, event_exhibit_tracking, event_file, event_importing, event_location, event_person, event_person_detail, event_person_tracking, event_presentation, event_presenter, event_registration, event_session, flask_cfg, fundraising, grant, hosted_file, log_client_viewing, lookup, membership_cfg, membership_group, membership_person_group, membership_person, membership_person_profile, membership_type, membership_person_type, order, order_v3, order_line, order_cart, organization, page, person, person_user, post, post_comment, product, qr, site, site_domain, user, util_email, websockets_redis, e_confex, e_cvent, e_impexium, e_stripe -# from app.routers import agent_bridge -# cont_edu_cert, cont_edu_cert_person, - -# from app.routers import aether_cfg, sql +# Centralized router registry +from app.routers.registry import setup_routers from app.db_sql import sql_select, reset_redis # , sql_connect @@ -102,18 +95,6 @@ app.mount('/static', StaticFiles(directory='static'), name='static') # Register all application routes setup_routers(app) -# Legacy registration block being removed... -# Set up each route once the router has been imported -# app.include_router( -# ae_obj.router, -# prefix='/ae_obj', -# tags=['AE Object'], -# ) -app.include_router( - aether_cfg.router, - tags=['Aether Config'], -) - # BEGIN: CORS # NOTE: Eventually this should query the DB for the specific list based on the cfg table and or site_domain table. That way it is dynamic and only allowing those defined in the DB. No wildcards or regex. @@ -133,33 +114,8 @@ app.add_middleware( # END: CORS -@app.on_event('startup') -async def startup(): - log.setLevel(logging.INFO) # DEBUG, INFO, WARN, WARNING, ERROR, EXCEPTION, CRITICAL - log.debug(locals()) - - log.info('The Aether FastAPI API is starting up...') - #await database.connect() - - -@app.on_event('shutdown') -async def shutdown(): - log.setLevel(logging.INFO) # DEBUG, INFO, WARN, WARNING, ERROR, EXCEPTION, CRITICAL - log.debug(locals()) - - log.info('The Aether FastAPI API is shutting down...') - #await database.disconnect() - - -#Add the processing time to the response header. -@app.middleware('http') -async def add_process_time_header(request: Request, call_next): - import time - start_time = time.time() - response = await call_next(request) - process_time = time.time() - start_time - response.headers['X-Process-Time'] = str(process_time) - return response +# Register utility middleware from external module +app.middleware('http')(process_time_middleware) # ### BEGIN ### API Main ### fastapi_root() ###