CORS Header Generator
Configure your CORS policy and get ready-to-use headers for Express, Nginx, Apache, and Cloudflare Workers. Handles credentials, preflight caching, and wildcard restrictions.
Configuration
Use * for public APIs. Use specific origin when credentials=true.
Access-Control-Allow-Origin: * with Allow-Credentials: true. Change origin to a specific URL.
HTTP Headers
Frequently Asked Questions
What CORS headers do I need for a public API?▼
For a fully public API (no credentials): Access-Control-Allow-Origin: *, Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS, and Access-Control-Allow-Headers for any custom headers. Add Access-Control-Max-Age to cache the preflight response. Never use * with credentials.
Why use Access-Control-Max-Age?▼
Browsers send an OPTIONS preflight before non-simple cross-origin requests. Access-Control-Max-Age tells the browser how long (in seconds) to cache the preflight result, avoiding repeated OPTIONS requests. A value of 86400 (24 hours) is common for APIs that rarely change their CORS policy.
Can I allow multiple origins?▼
The CORS spec allows only one origin value per response (or *). To support multiple origins, check the incoming Origin header against a server-side allowlist and reflect it back if it matches. This tool generates the headers for a single origin — implement allowlist logic in your server code.
What is the difference between Allow-Headers and Expose-Headers?▼
Access-Control-Allow-Headers lists which request headers browsers can send (checked during preflight). Access-Control-Expose-Headers lists which response headers JavaScript can read via fetch response.headers.get(). By default, only a small set of 'safe' response headers are readable.
When is a preflight triggered?▼
Preflight (OPTIONS) is triggered when: the method is PUT/DELETE/PATCH, the Content-Type is application/json (or anything other than form types), or custom headers like Authorization are sent. GET with only standard headers is 'simple' and doesn't require a preflight.
Related Products
on GumroadDevPlaybook Interview Vault
210+ real technical interview questions with model answers, asked at Google, Meta, Amazon, Microsoft, Stripe, and Shopify. Covers Frontend (55), Backend (55), System Design (50), and DSA (50). Available in English and Traditional Chinese.
Buy on Gumroad →TypeScript Quick Reference Toolkit
5 practical reference files for TypeScript developers: cheatsheet, TS vs JS comparison, 20 utility types with real examples, tsconfig best practices template, and 15 common mistakes guide. Print it. Keep it on your desk.
Buy on Gumroad →Developer Interview Vault
210 technical interview questions with model answers, key points, and follow-up questions. Covers Frontend, Backend, System Design, and DSA — bilingual English + Traditional Chinese (ZH-TW). PWYW from $29.
Buy on Gumroad →You Might Also Need
Webhook Tester
Generate realistic webhook test payloads for GitHub, Stripe, Slack, and custom services. Get a curl command to send the payload to your local endpoint. Inspect headers, payload size, and content-type.
Open free tool →
OpenAPI Validator
Paste your OpenAPI 3.x spec (YAML or JSON) to validate structure, find missing required fields, detect duplicate paths, check for missing operationIds, and get errors and warnings with path references.
Open free tool →
HTTP Status Code Reference
Complete HTTP status code reference. Search all 1xx, 2xx, 3xx, 4xx, and 5xx codes with plain-English descriptions, real-world use cases, and when to use each in REST APIs.
Open free tool →
More Free Tools
Related Articles
API Rate Limiting: Algorithms and Implementation Guide 2026
Complete guide to API rate limiting in 2026. Token Bucket, Leaky Bucket, Sliding Window algorithms with Node.js and Redis implementations, distributed rate limiting, 429 handling, and best practices.
Base64 Encoding Explained: When to Use It and When to Avoid It
Base64 encoding explained: when to use it in APIs, image data URIs, and auth tokens. Real-world examples and common pitfalls for web developers.
API Rate Limiting: Strategies, Algorithms, and Free Tools
A complete guide to API rate limiting in 2025: Fixed Window, Sliding Window, Token Bucket, and Leaky Bucket algorithms explained, with implementation in Node.js, Python, and Go, Redis-based distributed limiting, and client-side backoff strategies.
Complete HTTP Status Codes Reference for REST API Devs
The complete HTTP status codes reference for REST API developers. Every 1xx, 2xx, 3xx, 4xx, and 5xx code explained with real-world API examples and best practices.
HTTP Status Codes Explained: Complete Guide for Developers
Every HTTP status code group explained with real-world examples. Know exactly when to use 200, 201, 301, 401, 404, 429, 500, and more.
Enjoying this tool? Get more like it.
Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.
Unlock AI-Powered Dev Tools
- ⚡ AI Code Review, Doc Generator & SQL Builder
- ⚡ All premium templates & early access
- ⚡ Member discounts on Gumroad products
$9/mo after trial · Cancel anytime
Want the full toolkit?
Get DevPlaybook Pro
Every template, guide, boilerplate, and automation script in one bundle. 13 premium products — grab them all at once and save big.
MIT licensed · Instant download · No subscription
See what's included → Browse all deals →