Avatar ·

How does the Access-Control-Allow-Origin header work and how to fix CORS error?

Hello everyone! I'm a beginner in JavaScript and trying to make a request from the frontend to a different domain (weather API). I have simple code in vanilla JS: ```javascript fetch('https://api.example-weather.com/data') .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Error:', error)); ``` But in the browser console I see an error: > Access to fetch at 'https://api.example-weather.com/data' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. I read that I need to add the `Access-Control-Allow-Origin` header, but I don't understand where to add it: on the server or on the client? I tried adding it to fetch like this: