1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2026-06-05 19:15:30 -04:00
Files
jarv.is/app/api/hits/route.ts
T
2025-11-22 17:11:42 -05:00

30 lines
705 B
TypeScript

import { NextResponse } from "next/server";
import { getViewCounts } from "@/lib/views";
export const GET = async (): Promise<
NextResponse<{
total: {
hits: number;
};
pages: Array<{
slug: string;
hits: number;
}>;
}>
> => {
// note: while hits have been renamed to views in most places, this API shouldn't change due to it being snapshotted
const views = await getViewCounts();
const total = {
hits: Object.values(views).reduce((acc, curr) => acc + curr, 0),
};
const pages = Object.entries(views).map(([slug, views]) => ({
slug,
hits: views,
}));
pages.sort((a, b) => b.hits - a.hits);
return NextResponse.json({ total, pages });
};