Skip to content

Commit

Permalink
Merge pull request #133 from softeerbootcamp4th/feat/#125/RewardApi
Browse files Browse the repository at this point in the history
[fix] sharedLink 로직 수정
  • Loading branch information
subsub-e authored Aug 20, 2024
2 parents 3685da8 + ad13136 commit 4fcae89
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
29 changes: 26 additions & 3 deletions service/src/api/comment/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,38 @@ const postLike = commentId => {
};

const getEachComment = commentId => {
return get(`/comments/commentId?id=${commentId}`);
return get(`/comments/commentId/${commentId}`);
};

const getShortenLink = () => {
return get(`/shorten-url`);
};

const getRedirectLink = url => {
return get(`/redirect/${url}`);
const getRedirectLink = async commentId => {
const accessToken = localStorage.getItem('userInfo');

try {
const response = await fetch(
`https://hyundai-server.store/redirect/${commentId}`,
{
method: 'GET',
headers: {
'Content-Type': 'application/json',
...(accessToken && {
Authorization: `Bearer ${accessToken}`,
}),
},
credentials: 'include',
},
);

// 응답의 헤더에서 Location 값을 추출
const redirectUrl = response.headers.get('Location');
return redirectUrl;
} catch (error) {
console.error('API 호출 실패: ', error);
throw error;
}
};

export {
Expand Down
4 changes: 3 additions & 1 deletion service/src/pages/joinEvent/commentList/Redirect.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { useEffect } from 'react';
import { getRedirectLink } from '@/api/comment/index';
import { useParams } from 'react-router-dom';
import { useParams, useNavigate } from 'react-router-dom';

function Redirect() {
const navigate = useNavigate();
const { commentId } = useParams();
console.log(commentId);
const getLink = async () => {
const response = await getRedirectLink(commentId);
navigate(response);
console.log(response);
};

Expand Down

0 comments on commit 4fcae89

Please sign in to comment.