Demo: watching CORS fail and fixing it
On This Lesson 3 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
see the browser error and fix it for one origin. Prepares JNR-024-LAB1.
Draft outline details
Step by step
- 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.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.