From 7e5b28c75581d79b4fe7a51dc0bd30aa180e4e4a Mon Sep 17 00:00:00 2001 From: Chung-il Jung Date: Sat, 31 Aug 2024 23:03:33 +0900 Subject: [PATCH] fix: axios defaults baseURL --- src/api/ApiController.ts | 5 +---- src/api/etc.ts | 10 ++++------ src/main.tsx | 5 +++-- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/api/ApiController.ts b/src/api/ApiController.ts index e536b3f..709a1bd 100644 --- a/src/api/ApiController.ts +++ b/src/api/ApiController.ts @@ -6,14 +6,11 @@ import { isLoginStorage } from 'utils/loginStorage'; import { logout, refresh } from './etc'; -export const PROXY_URL = window.location.hostname === 'localhost' ? '/api' : '/proxy'; axios.defaults.withCredentials = true; const JwtInterceptors = () => { const [token, setToken] = useRecoilState(tokenState); - const instance = axios.create({ - baseURL: `${PROXY_URL}`, - }); + const instance = axios.create(); //액세스토큰 유효성 검사 const isAccessTokenValid = async () => { diff --git a/src/api/etc.ts b/src/api/etc.ts index 946db59..035bbb1 100644 --- a/src/api/etc.ts +++ b/src/api/etc.ts @@ -3,12 +3,10 @@ import axios from 'axios'; import type { ClientRefresh } from 'types/user'; import { removeStorage } from 'utils/loginStorage'; -import { PROXY_URL } from './ApiController'; - // 전공 선택 의존성때문에 따로 빼놓은 것 export const type = async (Authorization: string) => { try { - const { data } = await axios.get(`${PROXY_URL}/suwiki/majorType`, { + const { data } = await axios.get(`suwiki/majorType`, { headers: { Authorization }, }); @@ -21,7 +19,7 @@ export const type = async (Authorization: string) => { export const searchFavorite = async (Authorization: string) => { try { - const { data } = await axios.get(`${PROXY_URL}/user/favorite-major`, { + const { data } = await axios.get(`user/favorite-major`, { headers: { Authorization }, }); @@ -35,7 +33,7 @@ export const searchFavorite = async (Authorization: string) => { // 로그아웃 export const logout = async () => { try { - const { data } = await axios.post(`${PROXY_URL}/user/client-logout`); + const { data } = await axios.post(`user/client-logout`); if (data.Success) { removeStorage('login'); window.location.href = '/'; @@ -49,7 +47,7 @@ export const logout = async () => { // 리프레시 export const refresh = () => { try { - const res = axios.post(`${PROXY_URL}/user/client-refresh`); + const res = axios.post(`user/client-refresh`); return res; } catch (error) { diff --git a/src/main.tsx b/src/main.tsx index db9f93b..0970e7c 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -12,6 +12,7 @@ import { ReactQueryDevtools } from 'react-query/devtools'; import { RecoilRoot } from 'recoil'; import App from './App'; + initialize('G-KG7KQ8K3GP'); export const queryClient = new QueryClient({ @@ -23,7 +24,7 @@ export const queryClient = new QueryClient({ }, }, }); -const PROXY_URL = window.location.hostname === 'localhost' ? '' : '/proxy'; +const PROXY_URL = window.location.hostname === 'localhost' ? '/api' : '/proxy'; axios.defaults.baseURL = PROXY_URL; axios.defaults.withCredentials = true; @@ -38,5 +39,5 @@ ReactDOM.createRoot(document.getElementById('root')!).render( - + , );