prisma
Unanswered
ordoumpozanis posted this in #help-forum
Hi i am using Prisma with Next 14 in order to fetch some data from a mongo database. Serve Cashed data, not updated. anyone if could help please. thanks in advanced
app behavior:
app loads : client ask server data. Works fine
in the app, client ask for the data again . The server send back non updated data but the same (like cashed)
regress page: client ask data, server send now the correct data.
api route code
import { PrismaClient } from "@prisma/client";
import { NextRequest, NextResponse } from "next/server";
export const dynamic = "force-dynamic";
// Define the path to the JSON file
const prisma = new PrismaClient();
export async function GET(req: NextRequest) {
try {
// Fetch markers from the database
let markers = await prisma.point.findMany();
// Return the parsed data with status 200
return NextResponse.json(markers, { status: 200 });
} catch (error) {
// Handle errors (e.g., file not found, JSON parsing errors)
console.error("Error reading or parsing the points.json file:", error);
return NextResponse.json(
{ message: "Internal Server Error" },
{ status: 500 }
);
}
}
client side request
// load the targets
const fetchTargets = useCallback(async () => {
try {
const response = await fetch("/api/getData", {
cache: "no-store",
});
if (response.ok) {
const data: MarkerProps[] = await response.json();
setTargets(data);
} else {
console.error("Failed to fetch targets:", response.statusText);
}
} catch (error) {
console.error("Error fetching targets:", error);
}
}, []);
notes
i have checked that the client indeed aks the route for data when an update is needed but the server send the cashed
app behavior:
app loads : client ask server data. Works fine
in the app, client ask for the data again . The server send back non updated data but the same (like cashed)
regress page: client ask data, server send now the correct data.
api route code
import { PrismaClient } from "@prisma/client";
import { NextRequest, NextResponse } from "next/server";
export const dynamic = "force-dynamic";
// Define the path to the JSON file
const prisma = new PrismaClient();
export async function GET(req: NextRequest) {
try {
// Fetch markers from the database
let markers = await prisma.point.findMany();
// Return the parsed data with status 200
return NextResponse.json(markers, { status: 200 });
} catch (error) {
// Handle errors (e.g., file not found, JSON parsing errors)
console.error("Error reading or parsing the points.json file:", error);
return NextResponse.json(
{ message: "Internal Server Error" },
{ status: 500 }
);
}
}
client side request
// load the targets
const fetchTargets = useCallback(async () => {
try {
const response = await fetch("/api/getData", {
cache: "no-store",
});
if (response.ok) {
const data: MarkerProps[] = await response.json();
setTargets(data);
} else {
console.error("Failed to fetch targets:", response.statusText);
}
} catch (error) {
console.error("Error fetching targets:", error);
}
}, []);
notes
i have checked that the client indeed aks the route for data when an update is needed but the server send the cashed