Files
EpicNext-Cms/src/app/api/home/route.ts
T
2026-07-13 21:57:41 +02:00

41 lines
1.1 KiB
TypeScript

import { apiJson } from "@/lib/api";
import { prisma } from "@/lib/prisma";
import { siteSettings } from "@/lib/services/site-settings";
export const dynamic = "force-dynamic";
/**
* GET /api/home — combined landing payload: the latest 4 website_articles and
* the current online player count (users.online === "1"). Mirrors the queries
* used by the public pages and the admin dashboard.
*/
export async function GET(_req: Request) {
let articles: unknown[] = [];
let online = 0;
let hotelName = "Atom";
try {
[articles, online, hotelName] = await Promise.all([
prisma.websiteArticles.findMany({
select: {
id: true,
title: true,
slug: true,
shortStory: true,
image: true,
createdAt: true,
},
orderBy: { createdAt: "desc" },
take: 4,
}),
prisma.user.count({ where: { online: "1" } }),
siteSettings.get("hotel_name", "Atom").then((v) => v ?? "Atom"),
]);
return apiJson({ articles, online, hotelName });
} catch {
// DB unavailable — return an empty payload instead of a 500.
return apiJson({ articles: [], online: 0, hotelName }, { status: 200 });
}
}