تبسيط CORS
في هذا الدرس 4 موضوعات
هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
في هذا الدرس
understand why browsers block some cross-origin calls.
الموضوعات المخطط لها
- An origin is scheme + host + port.
http://localhost:3000andhttp://localhost:8080are different origins. - Browsers apply the same-origin policy: a page may not read responses from another origin unless that server allows it.
- CORS is how the server allows it, with headers such as
Access-Control-Allow-Origin. - For some requests the browser first sends a preflight
OPTIONSrequest to ask permission. - CORS is enforced by browsers only. It does not protect your server from
curlor other programs.
تفاصيل المخطط المبدئي
عرض عملي
registry.addMapping("/**")
.allowedOrigins("https://shop.example.com")
.allowedMethods("GET", "POST", "PUT", "DELETE");اختبر فهمك
Does CORS stop a script on a server calling your API?
أظهر الإجابة
No; only browsers enforce it.
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.