<VirtualHost *:80>
    ServerName localhost
    DocumentRoot /var/www/html

    <Directory /var/www/html>
        AllowOverride All
        Require all granted
    </Directory>

    # Enable CORS for API endpoints
    <Directory "/var/www/html/api">
        Header set Access-Control-Allow-Origin "*"
        Header set Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS"
        Header set Access-Control-Allow-Headers "Content-Type, Authorization, X-Requested-With"
    </Directory>

    # Handle OPTIONS requests for CORS
    <FilesMatch "\.php$">
        SetEnvIf Request_Method "OPTIONS" CORs
    </FilesMatch>

    <IfModule mod_headers.c>
        Header always set Access-Control-Allow-Origin "*" env=CORs
        Header always set Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS" env=CORs
        Header always set Access-Control-Allow-Headers "Content-Type, Authorization, X-Requested-With" env=CORs
    </IfModule>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
