انتقل إلى المحتوى
أمين أبوزيد
درس مخطط لهJNR-024-L04

تبسيط CORS

  • الدرس 4 من 6
  • Junior
في هذا الدرس 4 موضوعات

هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.

نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.

في هذا الدرس

understand why browsers block some cross-origin calls.

الموضوعات المخطط لها

  • An origin is scheme + host + port. http://localhost:3000 and http://localhost:8080 are 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 OPTIONS request to ask permission.
  • CORS is enforced by browsers only. It does not protect your server from curl or other programs.
تفاصيل المخطط المبدئي

عرض عملي

java
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.

التطبيق

طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.

المختبر والتمارين الاختبار

تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.

اكتب للبحث في المستويات والمراحل والوحدات والدروس.