
    Mh                     0    d Z ddlmZmZmZ ddZd Zd Zy)zn
CORS utilities for the SQLGenAI application
This module centralizes CORS configuration for all API endpoints
    )requestjsonifycurrent_appc                 |   t         j                  j                  d      }|s(dt        j                  v rt        j                  d   }nd}| j                  j                  d|       |r| j                  j                  dd       | j                  j                  dd       | j                  j                  d	d
       | S )z
    Add CORS headers to a response
    
    Args:
        response: Flask response object
        allow_credentials: Whether to allow credentials
        
    Returns:
        Response with CORS headers
    OriginFRONTEND_URLzhttp://localhost:3001Access-Control-Allow-Originz Access-Control-Allow-CredentialstruezAccess-Control-Allow-Headersz-Content-Type, Authorization, X-Requested-WithzAccess-Control-Allow-MethodszGET, POST, PUT, DELETE, OPTIONS)r   headersgetr   configset)responseallow_credentialsorigins      /var/www/html/app/utils/cors.pyadd_cors_headersr      s     __  *F [/// ''7F,F 6??H 79hi79Z[O    c                  2    t        ddi      } t        |       S )zo
    Create a response for CORS preflight requests
    
    Returns:
        Response for OPTIONS requests
    statusok)r   r   r   s    r   cors_preflight_responser   *   s     $'(HH%%r   c                 R    | j                   j                  d      r| S t        |       S )z
    Add CORS headers to all responses
    Can be registered with Flask's after_request decorator
    
    Args:
        response: Flask response object
        
    Returns:
        Response with CORS headers
    r	   )r   r   r   r   s    r   cors_after_requestr   4   s)     9:H%%r   N)T)__doc__flaskr   r   r   r   r   r    r   r   <module>r      s"   
 0 / D&&r   