Chuyển tới nội dung chính
kitlocal.dev

Tạo CORS Header

Chạy cục bộ

Xử lý 100% ngay trong trình duyệt. Dữ liệu đầu vào và kết quả không rời khỏi thiết bị.

Tạo cấu hình CORS cho các máy chủ web và framework phổ biến

Access-Control-Allow-Methods
Các header phản hồi cách nhau bằng dấu phẩy được phép đọc từ JavaScript phía client.
Thời gian lưu cache preflight tính bằng giây (mặc định 86400).
Các Header phản hồi HTTP
Đoạn cấu hình Nginx Location
location /api/ {
    if ($request_method = 'OPTIONS') {
        add_header 'Access-Control-Allow-Origin' 'https://example.com';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'Content-Type, Authorization';
        add_header 'Access-Control-Max-Age' 86400;
        add_header 'Content-Type' 'text/plain; charset=UTF-8';
        add_header 'Content-Length' 0;
        return 204;
    }

    add_header 'Access-Control-Allow-Origin' 'https://example.com' always;
    add_header 'Access-Control-Allow-Credentials' 'true' always;
}