Articles

How to fix CORS errors without changing your backend code

Fix browser CORS errors with one command: the edge answers preflights and adds CORS headers, with no change to your API. Compared with Vercel, Render, Railway.

Updated

On Gregale, one command fixes a browser CORS error without touching your backend: gregale edge cors allow my-api https://app.example.com. Gregale's edge answers the browser's preflight and adds the CORS headers to your app's responses. The preflight OPTIONS request is answered with 204 at the edge, so it never wakes your app or reaches your code. Edge rules, CORS rules included, are in beta on every plan, Free included.

Fix it

bash
# Let your frontend call the API
gregale edge cors allow my-api https://app.example.com

# Several origins, and cookies or an Authorization header from the browser
gregale edge cors allow my-api https://app.example.com https://admin.example.com --credentials

# Allow one more request header your frontend sends
gregale edge cors allow my-api https://app.example.com --credentials --allow-header X-Request-Id

gregale edge cors list my-api
gregale edge cors delete <rule-id>

The defaults cover most APIs:

SettingDefault
MethodsGET, POST, PUT, PATCH, DELETE, OPTIONS
Request headers*; with --credentials: Accept, Authorization, Content-Type, X-Requested-With
Access-Control-Max-Age600 seconds (--max-age, at most 86400)
HostThe app's first verified custom domain, or its own address when it has none (--host)

Match the error to the fix

What the browser console saysFix
No Access-Control-Allow-Origin header is present on the requested resourceAllow the page's origin, exactly as the browser sends it: scheme, host and port
Response to preflight request doesn't pass access control checkYour app doesn't answer OPTIONS; the CORS rule answers it at the edge
The value of Access-Control-Allow-Origin must not be the wildcard * when credentials are includedList the origins and add --credentials
Request header field x-request-id is not allowedAdd --allow-header X-Request-Id

A CORS error is the browser's rule, not your server's: the same request from curl works. That is why the fix belongs in front of the app.

Full control with an edge rule

gregale edge cors allow creates a simple cors edge rule. For other methods, several hosts or a different path, write the rule yourself (POST /v1/apps/{slug}/edge-rules):

json
{
  "kind": "cors",
  "match_host": "api.example.com",
  "match_path": "/**",
  "action": {
    "allow_origins": ["https://app.example.com", "https://*.example.com"],
    "allow_methods": ["GET", "POST"],
    "allow_headers": ["Authorization", "Content-Type"],
    "allow_credentials": true,
    "max_age_seconds": 600
  }
}

An origin is *, https://host[:port], https://*.host for subdomains, or https://host:* for any port. To protect your users, * can't be combined with allow_credentials, and neither can a wildcard under a public suffix such as https://*.vercel.app or https://*.github.io, where anyone can register a name. On Hobby and above, a CORS preset (/v1/cors-presets) shares one origin list across several rules.

How other platforms compare

PlatformAdding CORS to a backend without changing its code
GregaleOne command; the edge answers the preflight and adds the headers, and preflights never wake the app
Vercelheaders in vercel.json set fixed headers; for preflights or an origin that varies by request, Vercel points to middleware or an OPTIONS route handler in your code
RenderCustom header rules are a static-site feature; a web service sends its own CORS headers
RailwayNo header setting; a Railway moderator says you would code your application to send those headers
Fly.iofly.toml can add fixed response headers, the same for every origin; the app still answers preflights

Checked against each vendor's public documentation and forum answers on November 27, 2026: Vercel: how to enable CORS, Render static site headers, Railway: adding custom HTTP headers, Fly.io response header modification.

Pricing

CORS rules cost nothing extra. They count toward your plan's edge rules per app: 5 on Free, 25 on Hobby ($10 a month), 100 on Pro ($30) and 500 on Scale ($99). Preflights answered at the edge never wake your app, so they add no running time. See Edge rules and Gregale pricing.

Questions

How do I fix a CORS error without changing my backend?

On Gregale, run gregale edge cors allow my-api https://app.example.com. Gregale’s edge then answers the browser’s preflight and adds the CORS headers to your app’s responses, so your code doesn’t change.

Does a CORS preflight wake a scaled-to-zero app?

Not on Gregale. A matched OPTIONS preflight is answered with 204 at the edge, without waking the app, so it adds no cold start and no running time.

Can I allow every origin and still send cookies?

No. * can’t be combined with allow_credentials, and neither can a wildcard under a public suffix such as https://.vercel.app. List your origins, or use a wildcard under your own domain such as https://.example.com.

Which Gregale plan includes CORS rules?

Every plan, Free included; edge rules are in beta. CORS rules count toward the plan’s edge rules per app: 5 on Free, 25 on Hobby, 100 on Pro and 500 on Scale.