Skip to content

Commit

Permalink
Feat: #63 Axios 기본 환경 설정 & Axios Instance 생성 Provider 정의
Browse files Browse the repository at this point in the history
  • Loading branch information
Seok93 committed Aug 15, 2024
1 parent af41e77 commit 81cff48
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/constants/units.ts
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;
27 changes: 27 additions & 0 deletions src/services/axiosProvider.ts
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,
});

0 comments on commit 81cff48

Please sign in to comment.