[JavaScript] "Access to fetch at 'https://api.example.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." 해결


[JavaScript]

문제상황: 웹 서비스 개발 중, 클라이언트에서 다른 도메인의 API를 호출하는 코드를 작성했습니다. 이때, CORS(Cross-Origin Resource Sharing) 관련 에러가 발생했습니다. 에러가 발생한 코드: fetch('https://api.example.com/data') .then((response) => response.json()) .then((data) => console.log(data)) .catch((error) => console.error('Error:', error));에러로그 내용: Access to fetch at 'https://api.example.com/data' from origin 'http://localhos..


원문링크 : [JavaScript] "Access to fetch at 'https://api.example.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." 해결