From c472261f34388a0b76c3e21fec494b8d5f304715 Mon Sep 17 00:00:00 2001 From: Mqdd Date: Wed, 26 Nov 2025 13:47:31 +0700 Subject: popular product now ssr --- src/api/productApi.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'src/api/productApi.js') diff --git a/src/api/productApi.js b/src/api/productApi.js index dc96a77e..b5f47bcf 100644 --- a/src/api/productApi.js +++ b/src/api/productApi.js @@ -1,5 +1,6 @@ import axios from 'axios'; +// CLIENT MODE → untuk useQuery export const popularProductApi = () => { return async () => { const today = new Date(); @@ -7,9 +8,25 @@ export const popularProductApi = () => { (today - new Date(today.getFullYear(), 0, 0)) / 86400000 ); const page = (dayOfYear % 24) + 1; - const dataPopularProducts = await axios( + + const res = await axios( `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/search?q=*&page=${page}&orderBy=stock&priceFrom=1` ); - return dataPopularProducts.data.response; + return res.data.response; }; }; + +// SERVER MODE → untuk SSR +export async function popularProductApiSSR() { + const today = new Date(); + const dayOfYear = Math.floor( + (today - new Date(today.getFullYear(), 0, 0)) / 86400000 + ); + const page = (dayOfYear % 24) + 1; + + const res = await axios( + `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/search?q=*&page=${page}&orderBy=stock&priceFrom=1` + ); + + return res.data.response || null; +} -- cgit v1.2.3