-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,13 @@ | ||
// axios의 인스턴스 구현체가 있고 전반적으로 instance를 이용해서 api 콜하는 함수들 | ||
|
||
export {}; | ||
import apiInstance from './instance.api'; | ||
|
||
const APIS = { | ||
// 아래는 예시 | ||
getPosts: async () => { | ||
const { data } = await apiInstance.get('/posts'); | ||
return data; | ||
}, | ||
}; | ||
|
||
export default APIS; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import axios, { type AxiosInstance } from 'axios'; | ||
|
||
const BASE_URL = 'https://api.10mm.today'; | ||
const BASE_TIMEOUT = 10000; | ||
|
||
const setInterceptors = (instance: AxiosInstance) => { | ||
instance.interceptors.request.use( | ||
(config) => { | ||
return config; | ||
}, | ||
(error) => { | ||
return Promise.reject(error); | ||
}, | ||
); | ||
|
||
instance.interceptors.response.use( | ||
(response) => { | ||
return response; | ||
}, | ||
(error) => { | ||
return Promise.reject(error); | ||
}, | ||
); | ||
|
||
return instance; | ||
}; | ||
|
||
const axiosInstance = setInterceptors( | ||
axios.create({ | ||
baseURL: BASE_URL, | ||
timeout: BASE_TIMEOUT, | ||
}), | ||
); | ||
|
||
export default axiosInstance; |