CORS (Cross-Origin Resource Sharing) เป็นกลไกความปลอดภัยของเบราว์เซอร์ที่ควบคุมว่าเพจเว็บจาก origin หนึ่งสามารถส่งคำขอไปยังเซิร์ฟเวอร์บน origin ที่แตกต่าง ได้หรือไม่ โดยค่าเริ่มต้น เบราว์เซอร์จะบล็อกคำขอข้ามแหล่งกำเนิด เซิร์ฟเวอร์ต้องอนุญาตให้ใช้อย่างชัดแจ้งผ่านส่วนหัว response
นโยบายเดียวกันแหล่งกำเนิดและปัญหา
Origin = scheme + host + port. These are DIFFERENT origins:
https://app.example.com → https://api.example.com (different host)
http://localhost:3000 → http://localhost:4000 (different port)
Browser blocks the cross-origin request UNLESS the server sends CORS headers allowing it.
