Skip to content

Commit a672f76

Browse files
committed
fix : 새로고침시 백엔드로 요청이 잘못 redirection오류 해결
새로고침시 백엔드로 redirection 요청이 잘못가던 오류 해결하기 위해서 vite.config.js (localhost의 redirection설정) /public/_redireciton(netlify의 redirection설정)파일 수정
1 parent 78bbf09 commit a672f76

6 files changed

+50
-75
lines changed

public/_redirects

+2-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
/auth/* https://itpick.store/auth/:splat 200
2-
/user/* https://itpick.store/user/:splat 200
3-
/keyword/search* https://itpick.store/keyword/search:splat 200
4-
/keyword* https://itpick.store/keyword:splat 200
5-
/rank/main-keywords https://itpick.store/rank/main-keywords 200
6-
/rank/reference* https://itpick.store/rank/reference:splat 200
7-
/rank* https://itpick.store/rank:splat 200
8-
/debate https://itpick.store/debate 200
9-
/debate/* https://itpick.store/debate/:splat 200
1+
/api/* https://itpick.store/:splat 200
2+
103
/* /index.html 200

src/apis/getCommunityRankingKeyword.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ import axios from 'axios';
22

33
export const getCommunityRankingKeyword = async () => {
44
try {
5-
const response = await axios.get('/rank/main-keywords', {
6-
7-
});
5+
const response = await axios.get('/api/rank/main-keywords', {});
86

97
return response.data.result;
108
} catch (error) {
119
console.error('홈 커뮤니티 별 랭킹 키워드 불러오는 중 오류 발생:', error);
1210
throw error;
1311
}
14-
};
12+
};

src/apis/getKeywordRelatedData.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@ interface Response {
1717
result: KeywordResult;
1818
}
1919

20-
export const getKeywordRelatedData = async (community: string, period: string, keyword: string) => {
20+
export const getKeywordRelatedData = async (
21+
community: string,
22+
period: string,
23+
keyword: string
24+
) => {
2125
try {
22-
const response = await axios.get<Response>('/rank/reference', {
26+
const response = await axios.get<Response>('/api/rank/reference', {
2327
params: {
2428
community: community,
2529
period: period,
@@ -34,4 +38,4 @@ export const getKeywordRelatedData = async (community: string, period: string, k
3438
console.error('키워드 관련자료 데이터를 가져오는 중 오류 발생:', error);
3539
throw error;
3640
}
37-
};
41+
};

src/apis/getRankingInfo.ts

+24-19
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@ interface Response {
2222
result: RankingResult;
2323
}
2424

25-
26-
export const getRankingInfo = async (community: string, period: string, date: string) => {
25+
export const getRankingInfo = async (
26+
community: string,
27+
period: string,
28+
date: string
29+
) => {
2730
try {
28-
const response = await axios.get<Response>('/rank', {
31+
const response = await axios.get<Response>('/api/rank', {
2932
params: {
3033
community: community,
3134
period: period,
@@ -35,25 +38,27 @@ export const getRankingInfo = async (community: string, period: string, date: st
3538

3639
console.log('랭킹 API 응답 데이터 확인', response.data);
3740

38-
const rankingList = response.data.result.rankingList.map((item: RankingItem) => {
39-
const tags = [
40-
item.nateRank !== -1 ? `네이트 ${item.nateRank}등` : '',
41-
item.naverRank !== -1 ? `네이버 ${item.naverRank}등` : '',
42-
item.zumRank !== -1 ? `줌 ${item.zumRank}등` : '',
43-
item.googleRank !== -1 ? `구글 ${item.googleRank}등` : '',
44-
item.namuwikiRank !== -1 ? `나무위키 ${item.namuwikiRank}등` : ''
45-
].filter(tag => tag !== ''); // 빈 문자열 제거
46-
47-
return {
48-
rank: item.rank,
49-
name: item.keyword,
50-
tags: tags
51-
};
52-
});
41+
const rankingList = response.data.result.rankingList.map(
42+
(item: RankingItem) => {
43+
const tags = [
44+
item.nateRank !== -1 ? `네이트 ${item.nateRank}등` : '',
45+
item.naverRank !== -1 ? `네이버 ${item.naverRank}등` : '',
46+
item.zumRank !== -1 ? `줌 ${item.zumRank}등` : '',
47+
item.googleRank !== -1 ? `구글 ${item.googleRank}등` : '',
48+
item.namuwikiRank !== -1 ? `나무위키 ${item.namuwikiRank}등` : '',
49+
].filter((tag) => tag !== ''); // 빈 문자열 제거
50+
51+
return {
52+
rank: item.rank,
53+
name: item.keyword,
54+
tags: tags,
55+
};
56+
}
57+
);
5358

5459
return rankingList;
5560
} catch (error) {
5661
console.error('랭킹 조회 중 오류:', error);
5762
throw error;
5863
}
59-
};
64+
};

src/apis/loginUser.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import axios from 'axios';
22

33
export const loginUser = async (email: string, password: string) => {
44
try {
5-
const response = await axios.post('/auth/login', {
6-
email, // encodeURIComponent 제거
7-
password, // encodeURIComponent 제거
5+
const response = await axios.post('/api/auth/login', {
6+
email, // encodeURIComponent 제거
7+
password, // encodeURIComponent 제거
88
});
99

1010
return response.data;
1111
} catch (error) {
12-
console.log("로그인 실패:",error);
12+
console.log('로그인 실패:', error);
1313
return null; //로그인 실패시 null 반환
14-
// throw error;
14+
// throw error;
1515
}
1616
};

vite.config.ts

+10-35
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { defineConfig } from 'vite'
2-
import react from '@vitejs/plugin-react-swc'
1+
import { defineConfig } from 'vite';
2+
import react from '@vitejs/plugin-react-swc';
33
import mkcert from 'vite-plugin-mkcert';
44

55
// https://vitejs.dev/config/
@@ -8,57 +8,32 @@ export default defineConfig({
88
react(),
99
mkcert({
1010
force: false,
11-
})
12-
13-
11+
}),
1412
],
1513
resolve: {
1614
alias: {
1715
'@images': '/src/assets/images',
1816
'@components': '/src/components',
1917
'@utils': '/src/utils',
20-
'@apis': '/src/apis',
18+
'@apis': '/src/apis',
2119
'@pages': '/src/pages',
2220
'@store': '/src/store',
2321
'@hooks': '/src/hooks',
24-
}
22+
},
2523
},
2624
server: {
27-
https:{
25+
https: {
2826
key: 'cert/localhost-key.pem',
2927
cert: 'cert/localhost.pem',
3028
},
3129
proxy: {
32-
'/auth': {
33-
target: 'https://itpick.store',
34-
changeOrigin: true,
35-
secure: false,
36-
rewrite: (path) => path.replace(/^\/auth/, '/auth')
37-
},
38-
'/user': {
39-
target: 'https://itpick.store',
40-
changeOrigin: true,
41-
secure: false,
42-
rewrite: (path) => path.replace(/^\/user/, '/user')
43-
},
44-
'/rank': {
45-
target: 'https://itpick.store',
46-
changeOrigin: true,
47-
secure: false,
48-
rewrite: (path) => path.replace(/^\/rank/, '/rank')
49-
},
50-
'/keyword': {
51-
target: 'https://itpick.store',
52-
changeOrigin: true,
53-
secure: false,
54-
rewrite: (path) => path.replace(/^\/keyword/, '/keyword')
55-
},
56-
'/debate': {
30+
'/api': {
5731
target: 'https://itpick.store',
5832
changeOrigin: true,
33+
// '/api' 제거
34+
rewrite: (path) => path.replace(/^\/api/, ''),
5935
secure: false,
60-
rewrite: (path) => path.replace(/^\/debate/, '/debate')
6136
},
6237
},
6338
},
64-
})
39+
});

0 commit comments

Comments
 (0)