Skip to content
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
6 changes: 1 addition & 5 deletions .env.production
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
# 프로덕션 환경에서 사용할 API 기본 URL
# 현재 CORS 문제로 인해 빈 값으로 설정 (상대 경로 사용)
VITE_API_BASE_URL=

# 백엔드 CORS 설정이 완료되면 아래 주석을 해제하고 위 라인을 주석 처리하세요
# VITE_API_BASE_URL=https://zerojae175-dev.store
VITE_API_BASE_URL=https://zerojae175-dev.store
47 changes: 45 additions & 2 deletions src/api/Home.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,49 @@
import axios from "axios";

export const fetchProducts = async () => {
const response = await axios.get("api/products");
// 개발 환경에서는 프록시 사용, 배포 환경에서는 실제 API URL 사용
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || "";

export interface ProductResponse {
id: number;
title: string;
price: number;
imageUrl: string;
}

export interface ReviewResponse {
id: number;
authorName: string;
rating: number;
comment: string;
imageUrls: string;
createdAt: string;
}

export interface ApiResponse {
success: boolean;
response: ProductResponse[];
error: null | string;
}

export interface ReviewApiResponse {
success: boolean;
response: ReviewResponse[];
error: null | string;
}

export const fetchProducts = async (): Promise<ApiResponse> => {
const response = await axios.get(`${API_BASE_URL}/api/products`);
console.log("Fetched products:", response.data);
return response.data;
};

export const fetchProductsReview1 = async (): Promise<ReviewApiResponse> => {
const response = await axios.get(`${API_BASE_URL}/api/products/1/reviews`);
console.log("Fetched reviews for product 1:", response.data);
return response.data;
};

export const fetchProductsReview2 = async (): Promise<ReviewApiResponse> => {
const response = await axios.get(`${API_BASE_URL}/api/products/2/reviews`);
return response.data;
};
Loading