Skip to content

Commit 8ae23b9

Browse files
authored
Merge pull request #195 from prgrms-web-devcourse-final-project/chore/193-baseurl
[chore] 개발 / 배포 api 분리
2 parents 5d4da15 + cd1d60d commit 8ae23b9

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

src/apis/auth.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import axios from 'axios';
22
import { axiosInstance } from './axios';
33
import { useAuthStore } from '@/store/authStore';
44

5+
const API_BASE_URL =
6+
import.meta.env.MODE === 'development'
7+
? '/api/auth/token' // ✅ 개발 환경에서는 프록시를 사용
8+
: import.meta.env.VITE_API_URL + '/api/auth/token'; // ✅ 배포 환경에서는 직접 API 호출
9+
510
// 로그인
611
export const login = async (loginId: string, password: string) => {
712
const { data } = await axiosInstance.post('/auth/login', {
@@ -25,7 +30,7 @@ export const postLogout = async () => {
2530

2631
// 토큰 재발급
2732
export const reissueToken = async () => {
28-
const { data } = await axios.post('/api/auth/token', {
33+
const { data } = await axios.post(`${API_BASE_URL}`, {
2934
withCredentials: true,
3035
});
3136

src/apis/axios.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@ import axios from 'axios';
22
import { useAuthStore } from '@/store/authStore';
33
import { reissueToken } from '@/apis/auth';
44

5+
const API_BASE_URL =
6+
import.meta.env.MODE === 'development'
7+
? '/api' // ✅ 개발 환경에서는 프록시를 사용
8+
: import.meta.env.VITE_API_URL + '/api'; // ✅ 배포 환경에서는 직접 API 호출
9+
510
export const axiosInstance = axios.create({
6-
baseURL: '/api',
11+
baseURL: API_BASE_URL,
712
withCredentials: true, // RT 자동 포함
813
});
914

@@ -50,14 +55,3 @@ axiosInstance.interceptors.response.use(
5055
return Promise.reject(error);
5156
},
5257
);
53-
54-
// .env에 추가하기
55-
// VITE_API_URL=http://43.203.98.65:8080
56-
57-
// 사용예시
58-
// const login = async () => {
59-
// const data = await axiosInstance.post('/user/login', {
60-
// loginId: 'test1234',
61-
// password: 'test1234!',
62-
// });
63-
// };

0 commit comments

Comments
 (0)