Skip to content

Instantly share code, notes, and snippets.

@duthied
Last active August 29, 2015 14:02
Show Gist options
  • Save duthied/0ceba52975cfc7ea5aed to your computer and use it in GitHub Desktop.
Save duthied/0ceba52975cfc7ea5aed to your computer and use it in GitHub Desktop.
Example preflight for CORs
if ($request_method = 'GET') {
add_header 'Access-Control-Allow-Origin' "$http_origin";
}
if ($request_method = 'POST') {
add_header 'Access-Control-Allow-Origin' "$http_origin";
}
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' "$http_origin";
add_header 'Access-Control-Max-Age' 3600;
add_header 'Access-Control-Allow-Methods' 'GET, PUT, PATCH, POST, DELETE, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'Authorization, Content-Type ,Accept, Origin, User-Agent, DNT, Cache-Control, Keep-Alive, X-Requested-With, If-Modified-Since';
# Help-out finicky browsers
add_header 'Content-Length' 0;
add_header 'Content-Type' 'text/plain charset=UTF-8';
return 204;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment