Open h-yabi2 opened 4 days ago
API_URL
を追加
API_URL=http://localhost:3000/api
src/app/(main)/page.tsx
cache: "no-store",
を指定してキャッシュを無効にしておく
~
import { TaskDocument } from "@/models/task";
~
const getAllTasks = async (): Promise<TaskDocument[]> => {
const response = await fetch(${process.env.API_URL}/tasks
, {
cache: "no-store",
});
if (response.status !== 200) {
throw new Error("Failed to fetch tasks");
}
const data = await response.json();
return data.tasks as TaskDocument[];
};
export default async function MainPage() { const allTasks = await getAllTasks(); ~
API 作成
src/app/api/tasks/route.ts