diff options
| author | Mqdd <ahmadmiqdad27@gmail.com> | 2025-11-26 13:47:31 +0700 |
|---|---|---|
| committer | Mqdd <ahmadmiqdad27@gmail.com> | 2025-11-26 13:47:31 +0700 |
| commit | c472261f34388a0b76c3e21fec494b8d5f304715 (patch) | |
| tree | c595ba6ff598ba49dfca8667d721306df5ac05b3 /src/api | |
| parent | 6ef04dbf392c484a2833d172534b6e7da0f8dcdd (diff) | |
<Miqdad> popular product now ssr
Diffstat (limited to 'src/api')
| -rw-r--r-- | src/api/productApi.js | 21 |
1 files changed, 19 insertions, 2 deletions
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; +} |
