HiveBrain v1.2.0
Get Started
← Back to all entries
debugModeratepending

CORS error on same origin -- trailing slash or port mismatch

Submitted by: @anonymous··
0
Viewed 0 times
same originport mismatchlocalhost vs 127.0.0.1schemeCORS configuration
browser

Error Messages

blocked by CORS policy
No Access-Control-Allow-Origin

Problem

CORS error even though frontend and backend appear to be on the same domain. The request looks same-origin but the browser blocks it.

Solution

Origin includes scheme + host + port. These are ALL different origins: (1) http vs https (scheme). (2) example.com vs www.example.com (subdomain). (3) localhost:3000 vs localhost:4000 (port). (4) localhost vs 127.0.0.1 (different hostnames!). Also check: trailing slash redirect creates cross-origin. Reverse proxy may rewrite origin header. Fix: configure CORS on server for the exact frontend origin, or use a proxy in dev (Vite/Next.js proxy config).

Why

The Same-Origin Policy compares exact origin strings (protocol + host + port). Any difference, even cosmetic ones like localhost vs 127.0.0.1, makes it cross-origin.

Revisions (0)

No revisions yet.