Files
EpicNext-Cms/src/app/api/home/route.ts
T
openhands 164a4f4ef6
CI / check (push) Failing after 39s
CI / release (push) Skipped
CI / deploy (push) Skipped
refactor: remove hotel-name fallback, fail fast when unconfigured
Drop the hardcoded FALLBACK_HOTEL_NAME ("Atom") preset and the brand.ts
module. HOTEL_NAME is now a required env var: if it (and the CMS hotel_name
setting) is missing the site fails validation at startup/build with a clear
message instead of silently rendering a placeholder hotel name.

resolveHotelName() resolves CMS hotel_name -> required HOTEL_NAME only.
Callers that used the preset (api/home route catch branch, CMS settings form
default, mobile-nav/logo-generator prop defaults) now use the configured name
or an empty default; the real name is already passed in by server parents.
2026-08-27 16:35:00 +02:00

46 lines
1.4 KiB
TypeScript

import { count, desc, eq } from "drizzle-orm";
import { env } from "@/env";
import { apiJson } from "@/lib/api";
import { db, User, WebsiteArticles } from "@/lib/db";
import { resolveHotelName } from "@/lib/hotel-name";
import { apiCacheKey, cacheSafe, redisCache } from "@/lib/redis-cache";
/**
* 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, onlineRows, hotelName] = await Promise.all([
db
.select({
id: WebsiteArticles.id,
title: WebsiteArticles.title,
slug: WebsiteArticles.slug,
shortStory: WebsiteArticles.shortStory,
image: WebsiteArticles.image,
createdAt: WebsiteArticles.createdAt,
})
.from(WebsiteArticles)
.orderBy(desc(WebsiteArticles.createdAt))
.limit(4),
db.select({ total: count() }).from(User).where(eq(User.online, "1")),
resolveHotelName(),
]);
return cacheSafe({
articles,
online: onlineRows[0]?.total ?? 0,
hotelName,
});
});
return apiJson(data);
} catch {
return apiJson(
{ articles: [], online: 0, hotelName: env.HOTEL_NAME },
{ status: 200 },
);
}
}