
    i	                         d dl Z d dlmZ d dlmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ d d	lmZmZmZ  e j&                  e      Zed
efd       ZdefdZdZy)    N)asynccontextmanager)FastAPI)CORSMiddleware)GZipMiddleware)settings)AuthenticationMiddleware)root_api_router)HTTPExceptionhttp_exception_handlerGlobalExceptionMiddlewareappc                j   K   t         j                  d       d t         j                  d       yw)z~
    Define FastAPI lifespan events (startup and shutdown).
    Handles database connection pool and other cleanup tasks.
    z&Execute FastAPI startup event handler.Nz'Execute FastAPI shutdown event handler.)loginfowarningr   s    -/var/www/html/ls-ibe-bot-apis/app/__init__.pylifespanr      s)      HH56 

 KK9:s   13returnc            	      (   t         j                  d       t        t        j                  t        j
                  ddt        j                   igt        j                  dk(  rt        j                  ndt        j                  dk(  rt        j                  ndt        j                  dk(  rt        j                  ndt              } | j                  t               | j                  t        d       t         j                  d	       | j                  t                t         j                  d
       | j#                  t$        t&               t         j                  d       | j                  t(               | j                  t*        dgdg ddg       | S )z)
    Initialize FastAPI application.
    z$Initialize FastAPI application node.urlzhttp://127.0.0.1:developmentN)titledebugserversdocs_url	redoc_urlopenapi_urlr   i  )minimum_sizezAdd application routes.z;Register global exception handler for custom HTTPException.zAdd authentication middleware.*T)GETPOSTPUTDELETEOPTIONSPATCH)allow_originsallow_credentialsallow_methodsallow_headers)r   r   r   r   PROJECT_NAMEDEBUGPORTENVDOCS_URL	REDOC_URLOPENAPI_URLr   add_middlewarer   r   include_routerr	   add_exception_handlerr
   r   r   r   r   s    r   get_applicationr5   +   s2    II45
##nn,X]]O<=>&.llm&C""(0(E($$4,4LLM,IH((tC 01~D9 II'(' IIKLm-CD II.//0eJe	   J    )r5   )logging
contextlibr   fastapir   fastapi.middleware.corsr   fastapi.middleware.gzipr   app.configsr   app.middleware.authenticationr   app.routersr	   app.exceptionsr
   r   r   	getLogger__name__r   r   r5   __all__ r6   r   <module>rD      sj     *  2 2   B '  g! ; ; ;(' 'R r6   