# What Is CORS and a Preflight Request? Explained for Developers
dev.to·22h·
Discuss: DEV
🔌APIs
Preview
Report Post

Ever deployed your Node.js API only to see Access to fetch has been blocked by CORS policy in the browser console? You’re not alone. CORS errors are among the most common frustrations for backend developers, yet the underlying mechanism is often misunderstood. Let’s fix that.

The Foundation: Same-Origin Policy

Browsers enforce a security mechanism called the Same-Origin Policy (SOP). It prevents JavaScript running on https://myapp.com from making requests to https://api.example.com unless explicitly allowed.

Origin = Protocol + Domain + Port

  • https://api.example.com:443 → Origin A
  • https://api.example.com:3000 → Origin B (different port)
  • http://api.example.com:443 → Origin C (different protocol)

Without SOP, malicious scripts on evil.com coul…

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help