TR-8, axios Default Setting
react 최상단의 index.js에서
axios.defaults
를 이용해 axiods의 defaullt setting를 할 수 있다.
http://localhost:4000 의 URL로 axios 요청을 보내다가
https://localhost:4000 의 URL로 변경하게 되면
모든 axios 요청에서 https로 변경해줘야 하는 번거로움이 있다.
하지만,
axios.defaults.baseURL = "https://localhost:4000"
으로 axios의 defaults baseURL을 설정해 놓으면,
URL을 바꿔야 할 때 defaults baseURL만 수정해주면 되는 것이다.
withCredentials
설정 역시 가능한데,
같은 방법으로 index.js에서
axios.defaults.withCredentials = true;
로 설정해 놓으면, 모든 axios 요청에서 withCredentials가 true로 설정된다.