blob: b5f47bcf7dca36ef1e4e5fc5c657c370473c90a6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
import axios from 'axios';
// CLIENT MODE → untuk useQuery
export const popularProductApi = () => {
return async () => {
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;
};
};
// 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;
}
|