Skip to content

Commit

Permalink
feat(nginx-core): streamline CORS handling in configuration template
Browse files Browse the repository at this point in the history
  • Loading branch information
alimd committed Nov 8, 2024
1 parent b5ab609 commit dc0cda2
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions nginx-core/etc/nginx/templates/location.d/70-cors.conf.template
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
# Method 1: Allow specific origin (Recommended for security)
add_header 'Access-Control-Allow-Origin' $NGINX_CORS_ORIGIN;

# Allow specific methods (GET, POST, PUT, DELETE, OPTIONS)
add_header 'Access-Control-Allow-Methods' $NGINX_CORS_METHODS;

# Allow specific headers
add_header 'Access-Control-Allow-Headers' $NGINX_CORS_HEADERS;

# Cache preflight requests for 24 hours (improves performance)
add_header 'Access-Control-Max-Age' $NGINX_CORS_MAXAGE;

# Handle OPTIONS requests (preflight requests for complex requests)
if ($request_method = 'OPTIONS') {
# Handle OPTIONS requests (preflight requests for complex requests)
add_header 'Access-Control-Allow-Origin' $NGINX_CORS_ORIGIN;
add_header 'Access-Control-Allow-Methods' $NGINX_CORS_METHODS;
add_header 'Access-Control-Allow-Headers' $NGINX_CORS_HEADERS;
add_header 'Access-Control-Max-Age' $NGINX_CORS_MAXAGE;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;

return 204;
}

0 comments on commit dc0cda2

Please sign in to comment.