From 3c31942c7caa6328616d33150b0dfd833250eca6 Mon Sep 17 00:00:00 2001 From: GuDoYoon Date: Wed, 2 Oct 2024 10:59:51 +0900 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=93=AC=20API(#30):=20=EC=9D=B8?= =?UTF-8?q?=EC=8A=A4=ED=84=B4=EC=8A=A4,=20=EC=9D=B8=ED=84=B0=EC=85=89?= =?UTF-8?q?=ED=84=B0=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- src/apis/instance.ts | 6 ++++++ src/apis/intercepter.ts | 20 ++++++++++++++++++++ src/apis/statusCode.ts | 1 + src/pages/main/Main.tsx | 6 ++++++ 5 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/apis/instance.ts create mode 100644 src/apis/intercepter.ts create mode 100644 src/apis/statusCode.ts diff --git a/.gitignore b/.gitignore index a547bf3..83e1c00 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,7 @@ yarn-debug.log* yarn-error.log* pnpm-debug.log* lerna-debug.log* - +.env node_modules dist dist-ssr diff --git a/src/apis/instance.ts b/src/apis/instance.ts new file mode 100644 index 0000000..f305030 --- /dev/null +++ b/src/apis/instance.ts @@ -0,0 +1,6 @@ +import axios from 'axios'; +const axiosConfig = axios.create({ + baseURL: import.meta.env.VITE_BASE_URL, + timeout: 5000, +}); +export default axiosConfig; diff --git a/src/apis/intercepter.ts b/src/apis/intercepter.ts new file mode 100644 index 0000000..c9cf6f3 --- /dev/null +++ b/src/apis/intercepter.ts @@ -0,0 +1,20 @@ +import axiosConfig from './instance'; +axiosConfig.interceptors.request.use(config => { + //요청 성공 직전 호출 + //헤더에 인가 토큰 부착 + //로컬스토리지에 저장한다고 가정한다면 + console.log('asdasd'); + const accessToken: string | null = localStorage.getItem('Token'); + if (accessToken !== null) { + config.headers.Authorization = `Bearer ${accessToken}`; + } + + return config; +}); +axiosConfig.interceptors.response.use( + //http status가 200번대인 경우 호출 + response => response, + error => { + //http status가 에러 코드인경우 실행 + } +); diff --git a/src/apis/statusCode.ts b/src/apis/statusCode.ts new file mode 100644 index 0000000..61a20b1 --- /dev/null +++ b/src/apis/statusCode.ts @@ -0,0 +1 @@ +export const HTTP_STATUS = {}; diff --git a/src/pages/main/Main.tsx b/src/pages/main/Main.tsx index 490465d..046c21d 100644 --- a/src/pages/main/Main.tsx +++ b/src/pages/main/Main.tsx @@ -1,6 +1,12 @@ import { GridDiv } from '../../style/gridSystem'; import { LayOutDiv, FeatureDiv } from './style'; +import axiosConfig from '../../apis/instance.ts'; export default function Main() { + const getUserDate = async () => { + const data = await axiosConfig.get('/users'); + console.log(data); + }; + getUserDate(); return ( From f250952e62521b4c63a05630727bb15d2e3aa6f6 Mon Sep 17 00:00:00 2001 From: bluetree7878 Date: Mon, 14 Oct 2024 18:44:36 +0900 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=90=9E=20BugFix(#49):=20ghcr=20passwo?= =?UTF-8?q?rd=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci-cd.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 897e74e..d2db205 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -18,13 +18,13 @@ jobs: runs-on: ubuntu-latest steps: # github repository에서 checkout - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 # docker build 수행 - name: Set up docker buildx id: buildx - uses: docker/setup-buildx-action@v1 + uses: docker/setup-buildx-action@v2 - name: Cache docker layers - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: /tmp/.buildx-cache key: ${{ runner.os }}-buildx-${{ env.VERSION }} @@ -36,7 +36,7 @@ jobs: with: registry: ghcr.io username: ${{ github.actor }} - password: ${{ secrets.GHCR_TOKEN }} + password: ${{ github.actor == 'bluetree7878' && secrets.bluetree7878_GHCR_TOKEN || secrets.rhehfl_ghcr_token }} - name: Build and push id: docker_build uses: docker/build-push-action@v2 @@ -56,7 +56,7 @@ jobs: with: registry: ghcr.io username: ${{ github.actor }} - password: ${{ secrets.GHCR_TOKEN }} + password: ${{ github.actor == 'bluetree7878' && secrets.bluetree7878_GHCR_TOKEN || secrets.rhehfl_ghcr_token }} # 3000 -> 80 포트로 수행하도록 지정 - name: Docker run run: | From 9714af4bc3b9fa0e16ce15dcacdb6ae6a6eb7f53 Mon Sep 17 00:00:00 2001 From: GuDoYoon Date: Wed, 16 Oct 2024 17:23:10 +0900 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=93=AC=20API(#30):=20react=20query=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20api=20=EA=B5=AC=EC=B6=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/admin/types/Quiz.ts | 2 +- src/apis/{ => axios}/instance.ts | 4 ++-- src/apis/{ => axios}/intercepter.ts | 0 src/apis/{ => axios}/statusCode.ts | 0 src/apis/quiz.ts | 15 +++++++++++++++ src/pages/main/Main.tsx | 9 ++++----- 6 files changed, 22 insertions(+), 8 deletions(-) rename src/apis/{ => axios}/instance.ts (58%) rename src/apis/{ => axios}/intercepter.ts (100%) rename src/apis/{ => axios}/statusCode.ts (100%) create mode 100644 src/apis/quiz.ts diff --git a/src/admin/types/Quiz.ts b/src/admin/types/Quiz.ts index ab86e4b..3b0bb55 100644 --- a/src/admin/types/Quiz.ts +++ b/src/admin/types/Quiz.ts @@ -1,6 +1,6 @@ export default interface Quiz { id?: number; - part: string; + part: 'EASY' | 'NORAML' | 'HARD' | 'VERY_HARD'; sectionId: number; title: string; question: string; diff --git a/src/apis/instance.ts b/src/apis/axios/instance.ts similarity index 58% rename from src/apis/instance.ts rename to src/apis/axios/instance.ts index f305030..3f39524 100644 --- a/src/apis/instance.ts +++ b/src/apis/axios/instance.ts @@ -1,6 +1,6 @@ import axios from 'axios'; -const axiosConfig = axios.create({ +const api = axios.create({ baseURL: import.meta.env.VITE_BASE_URL, timeout: 5000, }); -export default axiosConfig; +export default api; diff --git a/src/apis/intercepter.ts b/src/apis/axios/intercepter.ts similarity index 100% rename from src/apis/intercepter.ts rename to src/apis/axios/intercepter.ts diff --git a/src/apis/statusCode.ts b/src/apis/axios/statusCode.ts similarity index 100% rename from src/apis/statusCode.ts rename to src/apis/axios/statusCode.ts diff --git a/src/apis/quiz.ts b/src/apis/quiz.ts new file mode 100644 index 0000000..7cdf379 --- /dev/null +++ b/src/apis/quiz.ts @@ -0,0 +1,15 @@ +import { useQuery } from '@tanstack/react-query'; +import Quiz from '../admin/types/Quiz'; +import api from './axios/instance'; + +const QUIZ = { + getQuizzes: (sectionId: number, part: Quiz['part']) => { + return useQuery({ + queryKey: ['quizzes', { sectionId, part }], + queryFn: () => api.get(`/quizzes?sectionId=${sectionId}&part=${part}`), + gcTime: 5 * 60 * 1000, // 5분 + staleTime: 1 * 60 * 1000, // 1분 + }); + }, +}; +export default QUIZ; diff --git a/src/pages/main/Main.tsx b/src/pages/main/Main.tsx index 093ad29..f2bf05d 100644 --- a/src/pages/main/Main.tsx +++ b/src/pages/main/Main.tsx @@ -5,12 +5,11 @@ import { LayOutDiv, FeatureDiv, } from '../../style/LayOut'; +import QUIZ from '../../apis/quiz'; export default function Main() { - const getUserDate = async () => { - const data = await axiosConfig.get('/users'); - console.log(data); - }; - getUserDate(); + const { data: quizzes, isLoading } = QUIZ.getQuizzes(1, 'EASY'); + if (isLoading) return
asdasdasd
; + console.log(quizzes); return ( From 433c83957020d2d92a8c1b5c2aa2df541572564a Mon Sep 17 00:00:00 2001 From: GuDoYoon Date: Wed, 16 Oct 2024 17:37:23 +0900 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=93=AC=20API(#30):=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=EC=BD=94=EB=93=9C=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/main/Main.tsx | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/pages/main/Main.tsx b/src/pages/main/Main.tsx index f2bf05d..d17cba1 100644 --- a/src/pages/main/Main.tsx +++ b/src/pages/main/Main.tsx @@ -5,11 +5,7 @@ import { LayOutDiv, FeatureDiv, } from '../../style/LayOut'; -import QUIZ from '../../apis/quiz'; export default function Main() { - const { data: quizzes, isLoading } = QUIZ.getQuizzes(1, 'EASY'); - if (isLoading) return
asdasdasd
; - console.log(quizzes); return (