Cleanup: Finalize modularization of app/main.py
This commit is contained in:
52
app/main.py
52
app/main.py
@@ -15,18 +15,11 @@ from . import config
|
|||||||
import logging
|
import logging
|
||||||
import app.log
|
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
|
# Import middleware with alias to avoid shadowing 'app' FastAPI instance
|
||||||
from app.middleware import add_process_time_header as process_time_middleware
|
from app.middleware import add_process_time_header as process_time_middleware
|
||||||
|
|
||||||
# Import the routers here first:
|
# Centralized router registry
|
||||||
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.registry import setup_routers
|
||||||
# from app.routers import agent_bridge
|
|
||||||
# cont_edu_cert, cont_edu_cert_person,
|
|
||||||
|
|
||||||
# from app.routers import aether_cfg, sql
|
|
||||||
|
|
||||||
from app.db_sql import sql_select, reset_redis # , sql_connect
|
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
|
# Register all application routes
|
||||||
setup_routers(app)
|
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
|
# 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.
|
# 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
|
# END: CORS
|
||||||
|
|
||||||
|
|
||||||
@app.on_event('startup')
|
# Register utility middleware from external module
|
||||||
async def startup():
|
app.middleware('http')(process_time_middleware)
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
# ### BEGIN ### API Main ### fastapi_root() ###
|
# ### BEGIN ### API Main ### fastapi_root() ###
|
||||||
|
|||||||
Reference in New Issue
Block a user