-
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.
Feat: #63 Axios 기본 환경 설정 & Axios Instance 생성 Provider 정의
- Loading branch information
Showing
2 changed files
with
36 additions
and
0 deletions.
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,10 +1,19 @@ | ||
// ToDo: MEMORY_UNITS 으로 묶는거 고려해보기 | ||
export const KB = 1024; | ||
export const MB = 1024 * KB; | ||
export const GB = 1024 * MB; | ||
|
||
// ToDo: DeepFreeze로 변경할 것, 상수 정의 컨벤션 적용할 것 | ||
export const fileSizeUnits = Object.freeze([ | ||
{ unit: 'GB', value: GB }, | ||
{ unit: 'MB', value: MB }, | ||
{ unit: 'KB', value: KB }, | ||
{ unit: 'B', value: 1 }, | ||
]); | ||
|
||
// ToDo: TIME_UNITS 으로 묶는거 고려해보기 | ||
export const MILLISECOND = 1; | ||
export const SECOND = 1000 * MILLISECOND; | ||
export const MINUTE = 60 * SECOND; | ||
export const HOUR = 60 * MINUTE; | ||
export const DAY = 24 * HOUR; |
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,27 @@ | ||
import axios from 'axios'; | ||
import { SECOND } from '@constants/units'; | ||
import type { AxiosInstance, AxiosRequestConfig } from 'axios'; | ||
|
||
const JWT_TOKEN_DUMMY = | ||
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c'; | ||
|
||
const BASE_URL = import.meta.env.VITE_BASE_URL; | ||
const defaultConfigOptions: AxiosRequestConfig = { | ||
baseURL: BASE_URL, | ||
timeout: 10 * SECOND, | ||
headers: { 'Content-Type': 'application/json' }, | ||
}; | ||
|
||
export function axiosProvider(configOptions: AxiosRequestConfig = {}): AxiosInstance { | ||
return axios.create({ ...defaultConfigOptions, ...configOptions }); | ||
} | ||
|
||
// ToDo: authAxios에 로그인 기능 완료시 AccessToken, RefreshToken 처리 Interceptor 추가할 것 | ||
export const defaultAxios = axiosProvider(); | ||
export const authAxios = axiosProvider({ | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: JWT_TOKEN_DUMMY, | ||
}, | ||
withCredentials: true, | ||
}); |