chore: add nextjs template
This commit is contained in:
22
frontend-nextjs/lib/api.ts
Normal file
22
frontend-nextjs/lib/api.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
export type Product = {
|
||||
id: number;
|
||||
title: string;
|
||||
price_cents: number;
|
||||
image_url: string;
|
||||
};
|
||||
|
||||
export async function fetchProducts(): Promise<Product[]> {
|
||||
const res = await fetch("/api/products", { cache: "no-store" });
|
||||
if (!res.ok) {
|
||||
throw new Error("Failed to fetch products");
|
||||
}
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export async function fetchProduct(productId: string): Promise<Product> {
|
||||
const res = await fetch(`/api/products/${productId}`, { cache: "no-store" });
|
||||
if (!res.ok) {
|
||||
throw new Error("Failed to fetch product");
|
||||
}
|
||||
return res.json();
|
||||
}
|
||||
Reference in New Issue
Block a user