The common solution to handling CORS requests is as follow:
location ... {
add_header Access-Control-Allow-Origin ...;
add_header Access-Control-Allow-Credentials ...;
add_header Access-Control-Allow-Headers ...;
add_header Access-Control-Allow-Methods ...;
if ($request_method = 'OPTIONS') {
add_header Access-Control-Allow-Origin ...;
add_header Access-Control-Allow-Credentials ...;
add_header Access-Control-Allow-Headers ...;
add_header Access-Control-Allow-Methods ...;
return 204;
}
}
But if
is evil. Is it safe to use it this way?
UPD By the way, from what I can see, the duplicate add_header
's are not needed.