import { FALLBACK_HOTEL_NAME } from "@/lib/brand"; import { apiJson } from "@/lib/api"; import { resolveHotelName } from "@/lib/hotel-name"; import { prisma } from "@/lib/prisma"; import { redisCache, apiCacheKey } from "@/lib/redis-cache"; 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) { try { const data = await redisCache( apiCacheKey("home"), 15, async () => { const [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" } }), resolveHotelName(), ]); return { articles, online, hotelName }; }, ); return apiJson(data); } catch { return apiJson({ articles: [], online: 0, hotelName: FALLBACK_HOTEL_NAME }, { status: 200 }); } }