nginx handle OPTIONS request for api

  1. Handle OPTIONS request by nginx
  2. Send response 200

 


location / {
    if ($request_method = OPTIONS ) {
       add_header Access-Control-Allow-Origin "*";
       add_header Access-Control-Allow-Methods "POST, GET, PUT, DELETE, PATCH, OPTIONS";
       add_header Access-Control-Allow-Headers "origin, content-type, accept,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type";
       add_header Access-Control-Allow-Credentials "true";
       add_header Content-Length 0;
       add_header Content-Type text/plain;
       return 200;
    }
    try_files $uri /app.php$is_args$args;
}