codestates / codestates/book-log

[Error] 프론트에서 카카오 API 요청시 CORS가 발생함

Open
#58 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
1
Forks
5
PR merge metrics
No merged PRs in 30d

Description

### **어떤 에러인가요?**

- 프론트에서 카카오 API 요청을 보냈는데 CORS 에러가 발생함
- Postman으로 같은 API 요청을 보내면 결과가 잘 나옴

### **에러 메시지**

```
Access to XMLHttpRequest at 'https://dapi.kakao.com/v3/search/book?query=d' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.
```

### **에러 핸들링 방법**

- 카카오 API를 사용하는 방법이 있는 것 같아 `카카오 API CORS`로 구글링해봤다.
- 구글링 결과 카카오의 CORS 정책으로 인해 프론트에서 API 요청을 제한하고 있다는 것을 알았다.
- 때문에 프론트에서 직접 요청하는 대신, 서버에서 카카오 API를 요청하여 그 결과를 프론트로 전송해줘야 할 것 같다.
![Screenshot from 2021-12-18 01-11-42](https://user-images.githubusercontent.com/53068706/146575036-e97fe829-c90f-453e-a686-8f94c8b36848.png)

### **에러 핸들링을 위해 참고한 레퍼런스 링크**

[CORS(Cross-Origin Resource Sharing) 에러에 관해](https://kakao-tam.tistory.com/81)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.