
    Jf                         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
mZ  e j                  e      ZddZdd	Zdefd
ZdZy)    N)FastAPI)CORSMiddleware)settings)root_api_router)HTTPExceptionhttp_exception_handlerreturnc                  6   K   t         j                  d       yw)zDefine FastAPI startup event handler.

    Resources:
        1. https://fastapi.tiangolo.com/advanced/events/#startup-event

    z&Execute FastAPI startup event handler.Nlogdebug     ,/var/www/html/chat-with-data/app/__init__.py
on_startupr      s      II67   c                  6   K   t         j                  d       yw)zDefine FastAPI shutdown event handler.

    Resources:
        1. https://fastapi.tiangolo.com/advanced/events/#shutdown-event

    z'Execute FastAPI shutdown event handler.Nr   r   r   r   on_shutdownr      s      II78r   c                     t         j                  d       t        t        j                  t        j
                  ddigt        j                  t        gt        g      } | j                  t        dgdg ddg       t         j                  d	       | j                  t               t         j                  d
       | j                  t        t               | S )z)Initialize FastAPI application.
    
    z$Initialize FastAPI application node.urlzhttp://127.0.0.1:9000)titler   serversdocs_urlr   r   *T)GETPOSTPUTDELETEOPTIONSPATCH)allow_originsallow_credentialsallow_methodsallow_headerszAdd application routes.z;Register global exception handler for custom HTTPException.)r   r   r   r   PROJECT_NAMEDEBUGDOCS_URLr   r   add_middlewarer   include_routerr   add_exception_handlerr   r   )apps    r   get_applicationr,   '   s    
 II45
##nn012""< MC eJe	   II'('IIKLm-CDJr   )r,   )r	   N)loggingfastapir   fastapi.middleware.corsr   
app.configr   
app.routerr   app.exceptionsr   r   	getLogger__name__r   r   r   r,   __all__r   r   r   <module>r6      sJ      2  & g!		 8 r   