33 lines
1.0 KiB
TypeScript
33 lines
1.0 KiB
TypeScript
import * as Sentry from "@sentry/nextjs";
|
|
import { NextResponse } from "next/server";
|
|
import { getSummary } from "@/lib/analytics";
|
|
|
|
export const runtime = "nodejs";
|
|
export const dynamic = "force-dynamic";
|
|
|
|
function json<T>(data: T, init?: { status?: number } & ResponseInit) {
|
|
return NextResponse.json(data, init);
|
|
}
|
|
|
|
export async function GET(req: Request) {
|
|
try {
|
|
const { searchParams } = new URL(req.url);
|
|
const ownersLimit = Number(searchParams.get("ownersLimit") || "10") || 10;
|
|
|
|
const result = await Sentry.startSpan(
|
|
{ op: "db.query", name: "analytics.summary" },
|
|
async (span) => {
|
|
span.setAttribute("ownersLimit", ownersLimit);
|
|
const summary = await getSummary({ ownersLimit });
|
|
return summary;
|
|
},
|
|
);
|
|
|
|
return json(result);
|
|
} catch (error: unknown) {
|
|
Sentry.captureException(error);
|
|
const message = error instanceof Error ? error.message : String(error);
|
|
return json({ error: "Failed to fetch analytics summary", message }, { status: 500 });
|
|
}
|
|
}
|