From 433dbfa0510a614f64ebe788a86fda73046a3ae3 Mon Sep 17 00:00:00 2001 From: blcklamb Date: Fri, 21 Jul 2023 22:57:46 +0900 Subject: [PATCH 1/2] docs: gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index ec7df49..4a4d8c6 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,8 @@ # misc .DS_Store +.env.development +.env.production .env.local .env.development.local .env.test.local From 52a7cd7734edf082d745878f9fcedd8496b2c2bb Mon Sep 17 00:00:00 2001 From: blcklamb Date: Fri, 21 Jul 2023 22:59:04 +0900 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20api=20endpoint=20=EC=88=98=EC=A0=95?= =?UTF-8?q?=20-=20=EA=B0=9C=EB=B0=9C=20=ED=99=98=EA=B2=BD=EC=97=90?= =?UTF-8?q?=EC=84=9C=EB=8A=94=20proxy=EA=B0=80=20=EC=9E=91=EB=8F=99?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D,=20=EB=B0=B0=ED=8F=AC=20=ED=99=98?= =?UTF-8?q?=EA=B2=BD=EC=97=90=EC=84=9C=EB=8A=94=20BASE=5FURL=EC=9D=B4=20?= =?UTF-8?q?=EC=9E=98=20=EB=93=A4=EC=96=B4=EA=B0=80=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 6 +-- src/api/api.ts | 38 ++++--------------- src/api/consumer.ts | 8 +++- src/api/provider.ts | 23 ++++++----- .../provider/coupon/CreateCouponModal.tsx | 3 +- src/pages/Intro.tsx | 4 +- src/pages/ReactQuerySample.tsx | 25 ------------ 7 files changed, 32 insertions(+), 75 deletions(-) delete mode 100644 src/pages/ReactQuerySample.tsx diff --git a/src/App.tsx b/src/App.tsx index 2db0070..86faf4e 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -5,7 +5,6 @@ import Gift from "pages/Gift"; import Card from "pages/Card"; import GlobalStyle from "style/GlobalStyle"; import RecoilSample from "pages/RecoilSample"; -import ReactQuerySample from "pages/ReactQuerySample"; import IconLoader from "components/common/IconLoader"; import styled from "styled-components"; import Confirm from "pages/Confirm"; @@ -33,7 +32,6 @@ function App() { element={} /> } /> - } /> ); @@ -46,11 +44,9 @@ const Root = styled.div` justify-content: center; align-items: center; width: 390px; - height: 100%; + height: 100vh; margin: 0 auto; padding: 2rem; - - overflow-y: hidden; `; export default App; diff --git a/src/api/api.ts b/src/api/api.ts index f388a19..ebb2862 100644 --- a/src/api/api.ts +++ b/src/api/api.ts @@ -3,38 +3,9 @@ import { useMutation, useQuery } from "react-query"; // import { useMutation, useQuery } from "react-query"; import { CouponList } from "types/couponList.type"; import { GiftList } from "types/giftList.type"; -import type { Todos } from "types/todo.type"; axios.defaults.withCredentials = true; -export default async function fetchTodos(): Promise { - const response = await axios.get( - "https://jsonplaceholder.typicode.com/todos", - ); - return response.data; -} - -export async function postScrapeMetaData(url: string) { - const res = await axios({ - // url: "http://localhost:8080/scrape", - // url: "http://localhost:5151/scrape", - // url: "https://political-olive-radio.glitch.me/scrape", - url: "/scrape", // 이거다! - // axios.defaults.withCredentials = true; - method: "post", - data: { - url, - }, - }); - - console.log(res); - if (res.status === 200) { - console.log("test"); - return res.data; - } - throw new Error(res.statusText); -} - /** * * 주는 사람이 생성한 선물 목록을 확인하는 페이지에 진입할때 요청하는 api @@ -51,7 +22,9 @@ export async function getGiftList({ targetId, }: GETGiftListRequest): Promise { return axios - .get(`/api/gift/${targetId}`) + .get( + `${process.env.REACT_APP_BASE_URL}/gift/${targetId}`, + ) .then(response => response.data); } @@ -84,7 +57,10 @@ export async function postPickedGift( const { targetId, giftId } = params; const body = { targetId, giftId }; return axios - .post(`/target/${targetId}/pick`, { body }) + .post( + `${process.env.REACT_APP_BASE_URL}/target/${targetId}/pick`, + { body }, + ) .then(response => response.data); } diff --git a/src/api/consumer.ts b/src/api/consumer.ts index 247fbeb..eefab28 100644 --- a/src/api/consumer.ts +++ b/src/api/consumer.ts @@ -2,13 +2,17 @@ import axios from "axios"; import { GetCardInfo, GetTargetInfo } from "types/remote"; export const getCardInfo = async (targetId: number): Promise => { - const response = await axios.get(`/api/target/${targetId}`); + const response = await axios.get( + `${process.env.REACT_APP_BASE_URL}/target/${targetId}`, + ); return response.data; }; export const getTargetInfo = async ( targetId: number, ): Promise => { - const response = await axios.get(`/api/target/${targetId}/final`); + const response = await axios.get( + `${process.env.REACT_APP_BASE_URL}/target/${targetId}/final`, + ); return response.data; }; diff --git a/src/api/provider.ts b/src/api/provider.ts index ad815ce..b4275cd 100644 --- a/src/api/provider.ts +++ b/src/api/provider.ts @@ -1,12 +1,13 @@ import axios from "axios"; -export const API_URL = "https://api.picktime.store"; - // 선물 추가 export const postGift = async (giftUrl: string, targetId: string) => { - const response = await axios.post(`/api/gift/${targetId}`, { - giftUrl, - }); + const response = await axios.post( + `${process.env.REACT_APP_BASE_URL}/gift/${targetId}`, + { + giftUrl, + }, + ); // console.log(response.data.giftList); return response.data.giftList; }; @@ -18,10 +19,14 @@ interface PutGiftRequest { // 선물 수정 export const putGift = async ({ giftId, description }: PutGiftRequest) => { - const response = await axios.put(`/gift/${giftId}`, description, { - headers: { - "Content-Type": "multipart/form-data", + const response = await axios.put( + `${process.env.REACT_APP_BASE_URL}/gift/${giftId}`, + description, + { + headers: { + "Content-Type": "multipart/form-data", + }, }, - }); + ); console.log(response); }; diff --git a/src/components/provider/coupon/CreateCouponModal.tsx b/src/components/provider/coupon/CreateCouponModal.tsx index 4961386..bc1c5ba 100644 --- a/src/components/provider/coupon/CreateCouponModal.tsx +++ b/src/components/provider/coupon/CreateCouponModal.tsx @@ -16,7 +16,6 @@ import { toPng } from "html-to-image"; import Loading from "components/common/Loading"; import axios from "axios"; import { useParams } from "react-router-dom"; -// import { useParams } from "react-router-dom"; const BASIC_IMAGE_GRADIENT = [ "linear-gradient(133deg, #52ccff 0%, #5448e8 100%)", @@ -58,7 +57,7 @@ function CreateCouponModal({ setCloseCouponModal }: CreateCouponModalProps) { if (targetId) { const params = new URLSearchParams({ targetId }).toString(); await axios.post( - `/api/coupon?${params}`, + `${process.env.REACT_APP_BASE_URL}/coupon?${params}`, { formData }, { headers: { diff --git a/src/pages/Intro.tsx b/src/pages/Intro.tsx index b404b18..9c0970c 100644 --- a/src/pages/Intro.tsx +++ b/src/pages/Intro.tsx @@ -7,7 +7,9 @@ export default function Intro() { useEffect(() => { const fetchData = async () => { try { - const response = await fetch("/api/target/13/all"); // '/api' 경로로 요청을 보냅니다. + const response = await fetch( + `${process.env.REACT_APP_BASE_URL}/target/13/all`, + ); // '/api' 경로로 요청을 보냅니다. const jsonData = await response.json(); console.log(jsonData); } catch (error) { diff --git a/src/pages/ReactQuerySample.tsx b/src/pages/ReactQuerySample.tsx deleted file mode 100644 index 8621649..0000000 --- a/src/pages/ReactQuerySample.tsx +++ /dev/null @@ -1,25 +0,0 @@ -import fetchTodos from "api/api"; -import React from "react"; -import { useQuery } from "react-query"; -import type { Todos } from "types/todo.type"; - -export default function ReactQuerySample() { - const { isLoading, data } = useQuery("todos", fetchTodos); - - if (isLoading) { - return
Loading...
; - } - - return ( - <> -

Todos

- {data && ( -
    - {data.map(todo => ( -
  • {todo.title}
  • - ))} -
- )} - - ); -}