This commit is contained in:
2025-01-05 17:52:41 +01:00
parent ceb64d5251
commit 143bd821e5
14 changed files with 404 additions and 130 deletions

29
app/api/stats/route.ts Normal file
View File

@@ -0,0 +1,29 @@
// app/api/stats/route.ts
import { NextResponse } from "next/server";
const stats = {
views: 0,
projectsViewed: {} as { [key: string]: number },
};
export async function GET() {
return NextResponse.json(stats);
}
export async function POST(request: Request) {
const { type, projectId } = await request.json();
if (type === "page_view") {
stats.views += 1;
}
if (type === "project_view" && projectId) {
if (stats.projectsViewed[projectId]) {
stats.projectsViewed[projectId] += 1;
} else {
stats.projectsViewed[projectId] = 1;
}
}
return NextResponse.json({ message: "Stats updated", stats });
}