Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: api endpoint 수정 #91

Merged
merged 2 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

# misc
.DS_Store
.env.development
.env.production
.env.local
.env.development.local
.env.test.local
Expand Down
6 changes: 1 addition & 5 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -33,7 +32,6 @@ function App() {
element={<ConsumerResult />}
/>
<Route path="/recoil-sample" element={<RecoilSample />} />
<Route path="/react-query-sample" element={<ReactQuerySample />} />
</Routes>
</Root>
);
Expand All @@ -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;
38 changes: 7 additions & 31 deletions src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Todos[]> {
const response = await axios.get<Todos[]>(
"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
Expand All @@ -51,7 +22,9 @@ export async function getGiftList({
targetId,
}: GETGiftListRequest): Promise<GETGiftListResponse> {
return axios
.get<GETGiftListResponse>(`/api/gift/${targetId}`)
.get<GETGiftListResponse>(
`${process.env.REACT_APP_BASE_URL}/gift/${targetId}`,
)
.then(response => response.data);
}

Expand Down Expand Up @@ -84,7 +57,10 @@ export async function postPickedGift(
const { targetId, giftId } = params;
const body = { targetId, giftId };
return axios
.post<POSTPickedGiftResponse>(`/target/${targetId}/pick`, { body })
.post<POSTPickedGiftResponse>(
`${process.env.REACT_APP_BASE_URL}/target/${targetId}/pick`,
{ body },
)
.then(response => response.data);
}

Expand Down
8 changes: 6 additions & 2 deletions src/api/consumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ import axios from "axios";
import { GetCardInfo, GetTargetInfo } from "types/remote";

export const getCardInfo = async (targetId: number): Promise<GetCardInfo> => {
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<GetTargetInfo> => {
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;
};
23 changes: 14 additions & 9 deletions src/api/provider.ts
Original file line number Diff line number Diff line change
@@ -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;
};
Expand All @@ -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);
};
3 changes: 1 addition & 2 deletions src/components/provider/coupon/CreateCouponModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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%)",
Expand Down Expand Up @@ -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: {
Expand Down
4 changes: 3 additions & 1 deletion src/pages/Intro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
25 changes: 0 additions & 25 deletions src/pages/ReactQuerySample.tsx

This file was deleted.