Skip to content

Commit

Permalink
fix: axios defaults baseURL
Browse files Browse the repository at this point in the history
  • Loading branch information
tooooo1 committed Aug 31, 2024
1 parent 8da276c commit 7e5b28c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
5 changes: 1 addition & 4 deletions src/api/ApiController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
10 changes: 4 additions & 6 deletions src/api/etc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
});

Expand All @@ -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 },
});

Expand All @@ -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 = '/';
Expand All @@ -49,7 +47,7 @@ export const logout = async () => {
// 리프레시
export const refresh = () => {
try {
const res = axios.post<ClientRefresh>(`${PROXY_URL}/user/client-refresh`);
const res = axios.post<ClientRefresh>(`user/client-refresh`);

return res;
} catch (error) {
Expand Down
5 changes: 3 additions & 2 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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;
Expand All @@ -38,5 +39,5 @@ ReactDOM.createRoot(document.getElementById('root')!).render(
</RecoilRoot>
</QueryClientProvider>
</AsyncBoundary>
</React.StrictMode>
</React.StrictMode>,
);

0 comments on commit 7e5b28c

Please sign in to comment.