Solve laravel/lumen preflight problem(405 option method not allowed)

When send json post/get request use axios or other http client in browser, preflight will happen. It will cause a 405 error said option method not allowed.

Here is the solution with nginx,

add cors control into / location in your nginx conf file:

location / {
    if ($request_method = 'OPTIONS') {
        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
        add_header 'Access-Control-Allow-Headers' '*';
        # Tell client that this pre-flight info is valid for 20 days
        add_header 'Access-Control-Max-Age' 1728000;
        add_header 'Content-Type' 'text/plain charset=UTF-8';
        add_header 'Content-Length' 0;
        return 204;
    try_files $uri $uri/ /index.php?$query_string;