@@ -63,8 +63,8 @@ function filterProducts(products, query) {
6363}
6464
6565export const handlers = [
66- // 상품 목록 API (상대 경로)
67- http . get ( "/api/products" , async ( { request } ) => {
66+ // 상품 목록 API
67+ http . get ( "* /api/products" , async ( { request } ) => {
6868 const url = new URL ( request . url ) ;
6969 const page = parseInt ( url . searchParams . get ( "page" ) ?? url . searchParams . get ( "current" ) ) || 1 ;
7070 const limit = parseInt ( url . searchParams . get ( "limit" ) ) || 20 ;
@@ -111,7 +111,7 @@ export const handlers = [
111111 } ) ,
112112
113113 // 상품 상세 API
114- http . get ( "/api/products/:id" , ( { params } ) => {
114+ http . get ( "* /api/products/:id" , ( { params } ) => {
115115 const { id } = params ;
116116 const product = items . find ( ( item ) => item . productId === id ) ;
117117
@@ -133,76 +133,7 @@ export const handlers = [
133133 } ) ,
134134
135135 // 카테고리 목록 API
136- http . get ( "/api/categories" , async ( ) => {
137- const categories = getUniqueCategories ( ) ;
138- await delay ( ) ;
139- return HttpResponse . json ( categories ) ;
140- } ) ,
141-
142- // 절대 URL 패턴도 처리 (SSG용)
143- http . get ( "http://localhost:5174/api/products" , async ( { request } ) => {
144- const url = new URL ( request . url ) ;
145- const page = parseInt ( url . searchParams . get ( "page" ) ?? url . searchParams . get ( "current" ) ) || 1 ;
146- const limit = parseInt ( url . searchParams . get ( "limit" ) ) || 20 ;
147- const search = url . searchParams . get ( "search" ) || "" ;
148- const category1 = url . searchParams . get ( "category1" ) || "" ;
149- const category2 = url . searchParams . get ( "category2" ) || "" ;
150- const sort = url . searchParams . get ( "sort" ) || "price_asc" ;
151-
152- const filteredProducts = filterProducts ( items , {
153- search,
154- category1,
155- category2,
156- sort,
157- } ) ;
158-
159- const startIndex = ( page - 1 ) * limit ;
160- const endIndex = startIndex + limit ;
161- const paginatedProducts = filteredProducts . slice ( startIndex , endIndex ) ;
162-
163- const response = {
164- products : paginatedProducts ,
165- pagination : {
166- page,
167- limit,
168- total : filteredProducts . length ,
169- totalPages : Math . ceil ( filteredProducts . length / limit ) ,
170- hasNext : endIndex < filteredProducts . length ,
171- hasPrev : page > 1 ,
172- } ,
173- filters : {
174- search,
175- category1,
176- category2,
177- sort,
178- } ,
179- } ;
180-
181- await delay ( ) ;
182- return HttpResponse . json ( response ) ;
183- } ) ,
184-
185- http . get ( "http://localhost:5174/api/products/:id" , ( { params } ) => {
186- const { id } = params ;
187- const product = items . find ( ( item ) => item . productId === id ) ;
188-
189- if ( ! product ) {
190- return HttpResponse . json ( { error : "Product not found" } , { status : 404 } ) ;
191- }
192-
193- const detailProduct = {
194- ...product ,
195- description : `${ product . title } 에 대한 상세 설명입니다. ${ product . brand } 브랜드의 우수한 품질을 자랑하는 상품으로, 고객 만족도가 높은 제품입니다.` ,
196- rating : Math . floor ( Math . random ( ) * 2 ) + 4 ,
197- reviewCount : Math . floor ( Math . random ( ) * 1000 ) + 50 ,
198- stock : Math . floor ( Math . random ( ) * 100 ) + 10 ,
199- images : [ product . image , product . image . replace ( ".jpg" , "_2.jpg" ) , product . image . replace ( ".jpg" , "_3.jpg" ) ] ,
200- } ;
201-
202- return HttpResponse . json ( detailProduct ) ;
203- } ) ,
204-
205- http . get ( "http://localhost:5174/api/categories" , async ( ) => {
136+ http . get ( "*/api/categories" , async ( ) => {
206137 const categories = getUniqueCategories ( ) ;
207138 await delay ( ) ;
208139 return HttpResponse . json ( categories ) ;
0 commit comments