01What is CORS Header Builder?
CORS errors tend to show up late, usually right after a frontend moves to its own domain. This builder lets you choose your rules once and get the matching config for four places: raw response headers, the Express cors package, nginx and Apache. You pick Wildcard (*) or Specific Origins, toggle the methods, choose allowed request headers, and set Allow Credentials, Max-Age and any headers the browser should expose to JavaScript. The output updates as you change things. The rules come from the Fetch standard, which defines how browsers run CORS, and from MDN's CORS guide. The big one is that Access-Control-Allow-Origin holds a single origin or *, never a list. So when you add several origins, the tool doesn't join them with commas, because browsers reject that. It generates per-request matching instead. Express gets an origin array, which the cors package checks against each request. nginx gets a map on $http_origin that returns an empty value for unknown origins. Apache gets a SetEnvIf rule on the Origin header. Each echoes the requesting origin back only when it's on your list. Any specific origin also adds Vary: Origin, so a shared cache won't hand one site's response to another. Credentials can't be paired with *. In wildcard mode the tool leaves Access-Control-Allow-Credentials out, adds a comment saying why, and shows a warning. Origins are trimmed of trailing slashes and checked for the scheme://host[:port] shape. A Max-Age over 7200 triggers a note, because Chromium caps preflight caching at 2 hours and Firefox at 24. Take an example. You choose Specific Origins with https://app.example.com and https://admin.example.com/, turn on credentials, and expose X-Request-Id. The Headers tab tells you to echo the matching origin and adds Vary: Origin and Access-Control-Allow-Credentials: true. The trailing slash on the second origin is gone. There are limits. The nginx and Apache snippets answer every OPTIONS request with 204, and they don't check whether it's a real preflight. The nginx map has to live in the http block, so you can't paste the whole snippet into one location. Allowed headers and methods are sent the same way for every origin. The tool writes config and doesn't test a live server. Nothing leaves your browser.
Backend and DevOps engineers who need the same CORS rules written for Express, nginx or Apache without breaking credentialed requests from several frontends. The tool runs entirely in your browser, so your data never leaves your device.
02How to use CORS Header Builder
- Under Access-Control-Allow-Origin, choose Wildcard (*) or Specific Origins, and enter one origin per row, such as https://app.example.com.
- Under Access-Control-Allow-Methods, toggle the methods your API accepts.
- Under Access-Control-Allow-Headers, click common headers or type a custom one and add it.
- In Additional Options, set Allow Credentials, Max-Age (seconds) and any Expose Headers.
- Read any yellow warnings, switch between the Headers, Express, Nginx and Apache tabs, and click Copy Output.
03Worked examples
- Input:
Default settings: Wildcard (*), methods GET, POST, OPTIONS, headers Content-Type, Authorization, Max-Age 86400 (Headers tab) - Result:
Access-Control-Allow-Origin: * Access-Control-Allow-Methods: GET, POST, OPTIONS Access-Control-Allow-Headers: Content-Type, Authorization Access-Control-Max-Age: 86400 - These are the defaults the tool loads with.
- Input:
Same, with Allow Credentials turned on - Result:
Access-Control-Allow-Origin: * Access-Control-Allow-Methods: GET, POST, OPTIONS Access-Control-Allow-Headers: Content-Type, Authorization # Access-Control-Allow-Credentials left out: browsers reject it with Access-Control-Allow-Origin: * Access-Control-Max-Age: 86400 - The tool drops the credentials header instead of producing a config browsers refuse.
- Input:
Specific Origins https://app.example.com and https://admin.example.com/, credentials on, expose X-Request-Id (Headers tab) - Result:
# Send ONE origin per response: echo the request's Origin header # only when it exactly matches one of these, otherwise omit the header: # https://app.example.com # https://admin.example.com Access-Control-Allow-Origin: <matching request Origin> Vary: Origin Access-Control-Allow-Methods: GET, POST, OPTIONS Access-Control-Allow-Headers: Content-Type, Authorization Access-Control-Allow-Credentials: true Access-Control-Max-Age: 86400 Access-Control-Expose-Headers: X-Request-Id - The trailing slash on the second origin is removed.
- Input:
Same config, Express tab - Result:
app.use(cors({ origin: ['https://app.example.com', 'https://admin.example.com'], methods: ['GET', 'POST', 'OPTIONS'], allowedHeaders: ['Content-Type', 'Authorization'], credentials: true, maxAge: 86400, exposedHeaders: ['X-Request-Id'], })); - Trimmed: the require line and two comment lines above app.use are left out.
- Input:
Same config, Nginx tab - Result:
map $http_origin $cors_allow_origin { default ""; "https://app.example.com" $http_origin; "https://admin.example.com" $http_origin; } ... add_header 'Access-Control-Allow-Origin' $cors_allow_origin always; add_header 'Vary' 'Origin' always; ... if ($request_method = 'OPTIONS') { return 204; } - Trimmed. The map goes in the http block. nginx skips add_header when the value is empty, so unknown origins get no Allow-Origin header.
- Input:
Same config, Apache tab - Result:
SetEnvIf Origin "^(https://app\.example\.com|https://admin\.example\.com)$" CORS_ALLOW_ORIGIN=$1 <IfModule mod_headers.c> Header always set Access-Control-Allow-Origin "%{CORS_ALLOW_ORIGIN}e" env=CORS_ALLOW_ORIGIN Header always merge Vary Origin ... - Trimmed. Dots in the origins are escaped so the regex matches them literally.
04Common use cases
- Letting both app.example.com and admin.example.com call the same API with cookies, without falling back to *
- Adding CORS to an nginx reverse proxy in front of a service that doesn't handle it itself
- Writing the cors() options for an Express API, including exposedHeaders so the frontend can read X-Request-Id
- Fixing a credentialed fetch that fails because the server sends Access-Control-Allow-Origin: * with credentials
- Moving CORS rules from an old Apache .htaccess setup to Express while keeping the same origins and headers
- Checking why a cached response for one origin shows up on another, which usually means Vary: Origin is missing
05Tips
- Want cookies or an Authorization header to go along cross-origin? You need Specific Origins and credentials on, plus credentials: 'include' on the fetch call.
- In nginx, a location block with its own add_header lines drops the ones from the outer level. Repeat the CORS lines there.
- Content-Type: application/json or an Authorization header makes the browser send an OPTIONS preflight first. Make sure your server or proxy answers it.
- Response headers like X-Request-Id are hidden from JavaScript unless you list them under Expose Headers.
- Don't add null as an allowed origin. Sandboxed iframes and file: pages send it, so any site can produce it.
06Related concepts
Preflight request, Same-origin policy, Fetch standard, Vary header, Credentialed requests, Access-Control headers.
Frequently Asked Questions
What is CORS Header Builder?
CORS Header Builder is a free, browser-based developer tool on AIDToolStack. Visual CORS configuration builder with Express, Nginx, and Apache output. It requires no installation or sign-up and works entirely in your browser.
Is CORS Header Builder free to use?
Yes. No sign-up, no fees and no usage cap.
Does CORS Header Builder store my data?
No. It runs in your browser; nothing is uploaded.