openresty处理预检请求

server {
    # ...
    location /path {
        # ...
        more_set_headers 'Access-Control-Allow-Origin: *';
        more_set_headers 'Access-Control-Allow-Headers: *';
        more_set_headers 'Access-Control-Allow-Methods: *';
        more_set_headers 'Access-Control-Allow-Credentials: true';
        if ($request_method = 'OPTIONS') {
            # 缓存预检请求,减少预检请求的发起
            more_set_headers 'Access-Control-Max-Age: 3600';
            # 204 (no content)
            return 204;
        }
        # ...
    }
}

  

posted @ 2024-02-28 17:50  陶清刚  阅读(11)  评论(0)    收藏  举报