
    Ţid                        d dl Z d dlmZ d dlmZ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mZ  e j*                  e j,                  
        e j.                  e      Z e       Zedefd       Z edde      Zej;                  edgddgdg       ej=                  e       ej=                  e       ej=                  e       ej=                  e       ej?                  e       dede fd       Z!ejE                  d edd      d       edk(  r/d dl#Z# e#jH                  dejJ                  ejL                  d       yy)    N)asynccontextmanager)FastAPIRequest)CORSMiddleware)JSONResponse)StaticFiles)get_settings)init_db)auth_routerroom_routerchat_routergame_router)levelappc                   K   t                d{    t        dt        j                   dt        j                          d y7 7w)u0   应用生命周期：启动时初始化数据库Nu   🚀 Server running at http://:)r
   printsettingsSERVER_HOSTSERVER_PORT)r   s    F/mnt/c/Users/DipsyHou/Desktop/workspace/TheGreatWar/server/app/main.pylifespanr      s=      )OO	*8+?+?*@(BVBVAW
XY	 s   A
A8A
zThe Great War - Game Serverz0.1.0)titleversionr   *T)allow_originsallow_credentialsallow_methodsallow_headersrequestexcc                    K   t         j                  d| j                   d| j                   d| d       t	        dddt        |       d d	
      S w)NzUnhandled error on  z: T)exc_infoi  i  u   服务器内部错误: )codemessagedata)status_codecontent)loggererrormethodurlr   str)r    r!   s     r   global_exception_handlerr/   2   s[     
LL&w~~&6a}BseLW[L\,CCH:*NX\] s   AA/static)	directoryhtml)name__main__zapp.main:app)hostportreload)'logging
contextlibr   fastapir   r   fastapi.middleware.corsr   fastapi.responsesr   fastapi.staticfilesr   
app.configr	   app.databaser
   
app.routesr   r   r   r   basicConfigINFO	getLogger__name__r*   r   r   r   add_middlewareinclude_routerexception_handler	Exceptionr/   mountuvicornrunr   r        r   <module>rO      sd    * $ 2 * + #   I I   ',, '			8	$> 
 
 
 
'   %%%     ;    ;    ;    ;  y!G )  " 		#{XD9	 I zGKK!!!!	 rN   