Skip to content

Commit

Permalink
Merge pull request #89 from Nubblee/chore/envURL-86
Browse files Browse the repository at this point in the history
[Chore] api url 환경변수로 이동
  • Loading branch information
ssuminii authored Oct 23, 2024
2 parents 5c4b036 + 9a51e5d commit ffc2834
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 52 deletions.
2 changes: 1 addition & 1 deletion src/components/Banner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const Banner = () => {

const getCoteData = async () => {
const res = await axios.get(
`http://nubble-backend-eb-1-env.eba-f5sb82hp.ap-northeast-2.elasticbeanstalk.com/coding-problems?quizDate=${todayDate}`,
`${import.meta.env.VITE_NUBBLE_SERVER}/coding-problems?quizDate=${todayDate}`,
)
return res.data.problems
}
Expand Down
11 changes: 4 additions & 7 deletions src/hooks/useCheckSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@ const useCheckSession = () => {
return
}

await axios.get(
'http://nubble-backend-eb-1-env.eba-f5sb82hp.ap-northeast-2.elasticbeanstalk.com/auth/sessions/validate',
{
headers: {
'SESSION-ID': sessionId,
},
await axios.get(`${import.meta.env.VITE_NUBBLE_SERVER}/auth/sessions/validate`, {
headers: {
'SESSION-ID': sessionId,
},
)
})

console.log('로그인 된 상태')
} catch (error) {
Expand Down
6 changes: 2 additions & 4 deletions src/hooks/useCoteData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const testAuthor = [
},
]

const headers = { Authorization: `${process.env.GITHUB_TOKEN}` }
const headers = { Authorization: `${import.meta.env.VITE_GITHUB_TOKEN}` }
//문제 제목 공백 제거, 소문자로 통일시키는 함수
const normalizeString = (str: string) => {
return str
Expand Down Expand Up @@ -118,9 +118,7 @@ export const useCoteData = () => {

const fetchcoteDatas = async () => {
try {
const res = await axios.get(
`http://nubble-backend-eb-1-env.eba-f5sb82hp.ap-northeast-2.elasticbeanstalk.com/coding-problems`,
)
const res = await axios.get(`${import.meta.env.VITE_NUBBLE_SERVER}/coding-problems`)
setCoteDatas(res.data.problems)
fetchCommits()
} catch (error) {
Expand Down
16 changes: 6 additions & 10 deletions src/hooks/useFileUpload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@ const useFileUpload = () => {
try {
const formData = new FormData()
formData.append('file', file)

const res = await axios.post(
`http://nubble-backend-eb-1-env.eba-f5sb82hp.ap-northeast-2.elasticbeanstalk.com/files`,
formData,
{
headers: {
'Content-Type': 'multipart/form-data',
'SESSION-ID': sessionId,
},
console.log(`${import.meta.env.VITE_NUBBLE_SERVER}`)
const res = await axios.post(`${import.meta.env.VITE_NUBBLE_SERVER}/files`, formData, {
headers: {
'Content-Type': 'multipart/form-data',
'SESSION-ID': sessionId,
},
)
})
return res.data
} catch (error) {
setFailed('파일 업로드 실패')
Expand Down
17 changes: 6 additions & 11 deletions src/pages/AddQuestion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ const AddQuestion = () => {
useEffect(() => {
const getCodingTestList = async () => {
try {
const res = await axios.get(
'http://nubble-backend-eb-1-env.eba-f5sb82hp.ap-northeast-2.elasticbeanstalk.com/coding-problems',
)
const res = await axios.get(`${import.meta.env.VITE_NUBBLE_SERVER}/coding-problems`)
const data = res.data.problems.map((problem: any) => ({
id: problem.problemId, // problemId 필드를 id로 저장
quizDate: problem.quizDate,
Expand Down Expand Up @@ -95,7 +93,7 @@ const AddQuestion = () => {
const postCodingTest = async () => {
try {
const res = await axios.post(
'http://nubble-backend-eb-1-env.eba-f5sb82hp.ap-northeast-2.elasticbeanstalk.com/coding-problems',
`${import.meta.env.VITE_NUBBLE_SERVER}/coding-problems`,
{
quizDate: formData.quizDate,
problemTitle: formData.problemTitle,
Expand All @@ -119,14 +117,11 @@ const AddQuestion = () => {
const handleDelete = async (id: number) => {
try {
// DELETE 요청을 서버로 보냄
await axios.delete(
`http://nubble-backend-eb-1-env.eba-f5sb82hp.ap-northeast-2.elasticbeanstalk.com/coding-problems/${id}`,
{
headers: {
'SESSION-ID': sessionId,
},
await axios.delete(`${import.meta.env.VITE_NUBBLE_SERVER}/coding-problems/${id}`, {
headers: {
'SESSION-ID': sessionId,
},
)
})

// 성공적으로 삭제되면 클라이언트에서도 상태를 업데이트
const updatedQuestions = questions.filter((question) => question.id !== id)
Expand Down
13 changes: 5 additions & 8 deletions src/pages/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,12 @@ const Home: React.FC = () => {
return
}

const res = await axios.get(
'http://nubble-backend-eb-1-env.eba-f5sb82hp.ap-northeast-2.elasticbeanstalk.com/users/me',
{
headers: {
'Content-Type': 'application/json',
'SESSION-ID': sessionId,
},
const res = await axios.get(`${import.meta.env.VITE_NUBBLE_SERVER}/users/me`, {
headers: {
'Content-Type': 'application/json',
'SESSION-ID': sessionId,
},
)
})
console.log(res)
localStorage.setItem('userName', res.data.nickname)
localStorage.setItem('userId', res.data.username)
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const Login: React.FC = () => {
const getUser = async () => {
try {
const res = await axios.post(
'http://nubble-backend-eb-1-env.eba-f5sb82hp.ap-northeast-2.elasticbeanstalk.com/auth/sessions',
`${import.meta.env.VITE_NUBBLE_SERVER}/auth/sessions`,
{
username: id,
password: pw,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/PreviewPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const PreviewPage = () => {
const handleSubmit = async () => {
try {
await axios.post(
'http://nubble-backend-eb-1-env.eba-f5sb82hp.ap-northeast-2.elasticbeanstalk.com/posts',
`${import.meta.env.VITE_NUBBLE_SERVER}/posts`,
{
title: markdownTitle,
content: markdownContent,
Expand Down
15 changes: 6 additions & 9 deletions src/pages/WritePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,17 @@ const WritePage = () => {
}

const fetchCategory = async () => {
const res = await axios.get(
`http://nubble-backend-eb-1-env.eba-f5sb82hp.ap-northeast-2.elasticbeanstalk.com/categories`,
{
headers: {
'Content-Type': 'application/json',
},
const res = await axios.get(`${import.meta.env.VITE_NUBBLE_SERVER}/categories`, {
headers: {
'Content-Type': 'application/json',
},
)
})
setCategories(res.data.categories)
}

const fetchBoards = async (categoryId: string) => {
const res = await axios.get(
`http://nubble-backend-eb-1-env.eba-f5sb82hp.ap-northeast-2.elasticbeanstalk.com/categories/${categoryId}/boards`,
`${import.meta.env.VITE_NUBBLE_SERVER}/categories/${categoryId}/boards`,
{
headers: {
'Content-Type': 'application/json',
Expand All @@ -153,7 +150,7 @@ const WritePage = () => {
const handleDraft = async () => {
try {
const res = await axios.post(
'http://nubble-backend-eb-1-env.eba-f5sb82hp.ap-northeast-2.elasticbeanstalk.com/posts',
`${import.meta.env.VITE_NUBBLE_SERVER}/posts`,
{
title: markdownTitle,
content: markdownContent,
Expand Down

0 comments on commit ffc2834

Please sign in to comment.