
    ]i
                        d dl Z d dlmZmZmZ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 d dlmZ d dlmZ d dlmZ  e         ed	
      Zej7                  e e j8                  d      dd        e j8                  d      gZej7                  edgddgdg       ej=                  e
      dede
fd       Zej=                  e      defd       Z ejC                  d      d        Z"ejG                  eddg       ejG                  eddg       ejG                  eddg       ejG                  edd g       y)!    N)FastAPI	APIRouterDependsHTTPExceptionRequest)CORSMiddleware)RequestValidationError)JSONResponse)load_dotenv)router)SessionMiddlewarez+ContentWeaver: AI Assisted course Generator)titleSESSION_SECRET_KEYnoneT)
secret_key	same_site
https_onlyFRONT_APP_URL*)allow_originsallow_credentialsallow_methodsallow_headersrequestexcc                    K   |j                         D cg c]'  }dj                  d |d   D              |d   |d   d) }}t        dd|d   d	   |d   d
   d      S c c}w w)N.c              3   2   K   | ]  }t        |        y w)N)str).0locs     #/var/www/html/content_weaver/app.py	<genexpr>z6custom_validation_exception_handler.<locals>.<genexpr>(   s     ?3c#h?s   r!   msgtype)fieldmessager%   i  r   r'   r&   )statusr'   r&   status_codecontent)errorsjoinr
   )r   r   errorr,   s       r"   #custom_validation_exception_handlerr/   $   s      ZZ\ 	 XX?%,??U|&M	
F  ay+AYw'
 s   A%,A $A%c                    K   |j                   dk(  r|j                  dk(  rt        dddd      S t        |j                   |j                   |j                  d      S w)Ni  zNot authenticatedi  zMissing API Token)r(   r'   r)   )r*   detailr
   )r   r   s     r"   custom_http_exception_handlerr2   8   s]     
##**0C"C"/BC
 	
 OO??szzB s   AAhttpc                 n   K    ||        d {   }d|j                   d<   d|j                   d<   |S 7 $w)NALLOWALLzX-Frame-Optionszframe-ancestors *zContent-Security-Policy)headers)r   	call_nextresponses      r"   iframe_headersr9   D   s?     w''H*4H&'2EH./O (s   53%5z/courseCourse)prefixtagsz/userUserz/canvasz
Canvas LTIz/ltizCanvas LTI 1.3)$osfastapir   r   r   r   r   fastapi.middleware.corsr   fastapi.exceptionsr	   fastapi.responsesr
   dotenvr   routers.courser   course_routerrouters.useruser_routerrouters.canvascanvas_routerrouters.lti13lti13_routerstarlette.middleware.sessionsr   appadd_middlewaregetenvr   exception_handlerr/   r2   
middlewarer9   include_router     r"   <module>rU      su   	 G G 2 5 *  2 . 2 0 ; AB   ryy-.	   ryy)*   %%%   -.w E[  /& }%	m 	 &	     =(  D   ;wfX  >   =,  H   <6F5G  HrT   