x
This commit is contained in:
1 parent
aefa13e363
commit
1d55e979da
1 file changed
+4
-3
@@ -1,7 +1,8 @@
|
|||||||
import type { Article, Category, Order, Page, Product } from '@homaroma/types'
|
import type { Article, Category, Order, Page, Product } from '@homaroma/types'
|
||||||
import { API_BASE } from './api'
|
import { API_BASE } from './api'
|
||||||
|
|
||||||
const defaultRevalidate = 60
|
const isDev = process.env.NODE_ENV === 'development'
|
||||||
|
const defaultRevalidate = isDev ? 0 : 60
|
||||||
|
|
||||||
type ProductListResponse = {
|
type ProductListResponse = {
|
||||||
data?: Product[]
|
data?: Product[]
|
||||||
@@ -62,11 +63,11 @@ export async function fetchJsonResult<T>(path: string, init?: RequestInit & { ne
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getCategories(lang = 'all'): Promise<Category[]> {
|
export async function getCategories(lang = 'all'): Promise<Category[]> {
|
||||||
return await fetchJson<Category[]>(`/categories?lang=${lang}`, { next: { revalidate: 3600 } }) ?? []
|
return await fetchJson<Category[]>(`/categories?lang=${lang}`, { next: { revalidate: isDev ? 0 : 3600 } }) ?? []
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getCategoriesResult(lang = 'all'): Promise<ApiResult<Category[]>> {
|
export async function getCategoriesResult(lang = 'all'): Promise<ApiResult<Category[]>> {
|
||||||
return await fetchJsonResult<Category[]>(`/categories?lang=${lang}`, { next: { revalidate: 3600 } })
|
return await fetchJsonResult<Category[]>(`/categories?lang=${lang}`, { next: { revalidate: isDev ? 0 : 3600 } })
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getCmsPage(slug: string, lang = 'all'): Promise<Page | null> {
|
export async function getCmsPage(slug: string, lang = 'all'): Promise<Page | null> {
|
||||||
|
|||||||
Reference in new issue
Block a user