عرض عملي: مشاهدة فشل CORS وإصلاحه
في هذا الدرس 3 موضوعات
هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
في هذا الدرس
see the browser error and fix it for one origin. Prepares JNR-024-LAB1.
تفاصيل المخطط المبدئي
خطوة بخطوة
- Run Shop API on port 8080 and serve a small HTML page from another port (for example 3000) that calls
fetch("http://localhost:8080/products"). - Open the browser console and read the CORS error; check in the network tab that the server still answered.
- Configure CORS for exactly
http://localhost:3000and restart. - Planned mistake: use
allowedOrigins("*")together with credentials. Fix: list the explicit origin; the wildcard with credentials is not allowed and is unsafe. - Reload the page and see the call succeed; try from another origin (port 3001) and see it still fail.
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.