Skip to content

Commit

Permalink
[🔨 Refactor] axios 인스턴스 세팅 #194
Browse files Browse the repository at this point in the history
  • Loading branch information
dayannne committed Aug 10, 2023
1 parent 83d6bd9 commit 32f4eb6
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/api/axiosInstance/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { useRecoilValue } from 'recoil';
import { UserAtom } from '../../Store/userInfoAtoms';

const Constans = () => {
const userInfo = useRecoilValue(UserAtom);

const token = userInfo.token;
return token;
};

export const AUTH_TOKEN = Constans(); // 추출한 token값
export const BASE_URL = 'https://api.mandarin.weniv.co.kr/';
38 changes: 38 additions & 0 deletions src/api/axiosInstance/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import axios from 'axios';
import { AUTH_TOKEN, BASE_URL } from './constants';

// 기본 POST 요청 API
export const axiosApi = axios.create({
baseURL: BASE_URL,
headers: {
Authorization: `Bearer ${AUTH_TOKEN}`,
'Content-Type': 'application/json',
},
});

// req 없음, GET API 요청에 사용 (이미지 보기)
export const axiosUrlApi = axios.create({
baseURL: BASE_URL,
});

// '이미지 업로드' POST API 요청에 사용
export const axiosImgApi = axios.create({
baseURL: BASE_URL,
headers: { 'Content-Type': 'multipart/form-data' }, // 이미지 업로드 POST를 위해 form-data를 Content-type으로 설정
});

// token만 req, GET API 요청에 사용
export const axiosTokenApi = axios.create({
baseURL: BASE_URL,
headers: {
Authorization: `Bearer ${AUTH_TOKEN}`,
},
});

// Content-Type만 req, 회원가입, 로그인, 이메일 검증 등의 POST API 요청에 사용
export const axiosInfoApi = axios.create({
baseURL: BASE_URL,
headers: {
'Content-Type': 'application/json',
},
});

0 comments on commit 32f4eb6

Please sign in to comment.