Skip to main content

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.

✓ Handles credentials & wildcard conflict ✓ Code for 4 platforms ✓ Preflight (OPTIONS) included

Configuration

Use * for public APIs. Use specific origin when credentials=true.

HTTP Headers

 
Express.js
 

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.

Share this tool: X / Twitter LinkedIn
✓ 60,000+ developers use DevPlaybook ★★★★★ 4.8 / 5 on Gumroad ✓ MIT licensed · Instant download ✓ No login required

Related Products

on Gumroad

You Might Also Need

More Free Tools

Webhook Tester OpenAPI Validator HTTP Status Code Reference API Request Builder API Response Mock Generator HTTP Status Code Reference WebSocket Tester WebP Converter HTTP Status Code Lookup WebSocket Test Client HTTP Status Code Lookup API Response Time Tester HTTP Methods Reference OpenAPI Schema Validator OpenAPI Mock Generator API Test Case Generator Core Web Vitals Guide HTTP Headers Analyzer API Response Formatter & Analyzer HTTP API Tester HTTP Security Headers Generator HTTP Status Code Reference Web Vitals Scorer HTTP Header Analyzer Web Vitals Analyzer API Mock Server Config Generator REST API Request Builder HTTP Security Headers Checker API Response Mocker Core Web Vitals Budget Calculator API Rate Limit Calculator HTTP Headers Inspector HTTP Code Snippet Generator PWA Manifest Generator HTTP Mock Response Builder LLM Cost Calculator Haproxy Config Validator Caddy Caddyfile Generator HTTP Cache-Control Builder WASM Module Explorer AI Prompt Cost Calculator HTTP/2 Server Push Headers Builder Lighthouse Score Simulator Mock Service Worker (MSW) API Mocking Guide Core Web Vitals Calculator Content Security Policy Builder LLM Prompt Cost Calculator HTTP Header Inspector AI Rate Limit Calculator WebAssembly Binary Inspector Web Vitals Budget Planner HTTP Cache Header Builder Prompt Injection Tester GCP Service Account Key Auditor Web Performance Checklist Image Optimizer Checklist API Key Generator AI Doc Generator — Pro Tool AI System Guardian Color Blindness Simulator curl Command Builder .htaccess Generator Interview Question Generator JSON Diff Viewer JSON Diff JWT Builder JWT Decoder nginx Config Generator Password Strength Checker Developer Utilities Rate Limiter Tester API Changelog Generator Service Worker Generator HMAC Generator CSP Header Builder Rate Limit Calculator CORS Policy Builder AWS IAM Policy Validator WCAG Contrast Checker HTTP Cookie Parser HAR Diff Analyzer SBOM Generator JWT Debugger Pro Vue Component Generator LLM Context Window Calculator LLM Token Counter Dockerfile Linter Bundle Size Estimator SSL Certificate Checker Prompt Token Estimator nginx Config Builder Pulumi Modern IaC Guide Docker Layer Optimizer Bundle Size Impact Calculator HTML5 Canvas API Playground Token Context Calculator OpenAI Function Calling Generator TTFB Analyzer Token Counter & Cost Estimator AI API Rate Limit Calculator Password Strength Analyzer JWT Decoder & Validator

Enjoying this tool? Get more like it.

Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.

DevPlaybook Pro 7 days free

Unlock AI-Powered Dev Tools

  • ⚡ AI Code Review, Doc Generator & SQL Builder
  • ⚡ All premium templates & early access
  • ⚡ Member discounts on Gumroad products
Start Free Trial →

$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.

$79
$241 separately Save $162 (67% off)
Get DevPlaybook Pro — $79 →

MIT licensed · Instant download · No subscription

See what's included → Browse all deals →