Code: Select all
location /api/ {
try_files $uri /index.php$is_args$args;
# Handle PHP files
fastcgi_pass unix:/var/run/php/php8.3-fpm.sock; # Adjust PHP version
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/crumbsnet/api;
fastcgi_param REQUEST_URI $1;
include fastcgi_params;
# CORS headers
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE' always;
add_header 'Access-Control-Allow-Headers' 'Content-Type, Authorization, X-Requested-With' always;
# Handle preflight requests
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE';
add_header 'Access-Control-Allow-Headers' 'Content-Type, Authorization, X-Requested-With';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain; charset=utf-8';
add_header 'Content-Length' 0;
return 204;
}
}
Mobile version