nomadro/app/api/admin/overview/route.ts
eric 9f8fec1723 Ship portal PC/H5 acceptance, VIP ScrollReader, admin analytics and ops anchors.
Adds /api/health, ntfy notify on config save, /admin/analytics charts, and deploy smoke for miniprogram config/API.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-28 23:52:00 -05:00

83 lines
2.8 KiB
TypeScript

import { NextResponse } from "next/server";
import { requireAdminSession } from "~/lib/admin-auth";
import { createNomadroClient, PORTAL_ROUTES, SDK_VERSION } from "@nomadro/sdk";
import { resolvePocketBaseConfig } from "@nomadro/pb";
import { resolvePayProvider } from "@nomadro/pay";
import { readRemoteConfigFile } from "~/lib/remote-config-store";
async function probe(url: string, timeoutMs = 4000) {
const started = Date.now();
try {
const ctrl = new AbortController();
const t = setTimeout(() => ctrl.abort(), timeoutMs);
const res = await fetch(url, { signal: ctrl.signal, cache: "no-store" });
clearTimeout(t);
return { ok: res.ok, status: res.status, latencyMs: Date.now() - started };
} catch {
return { ok: false, status: 0, latencyMs: Date.now() - started };
}
}
export async function GET() {
if (!(await requireAdminSession())) {
return NextResponse.json({ ok: false, error: "unauthorized" }, { status: 401 });
}
const client = createNomadroClient();
const pb = resolvePocketBaseConfig();
const pay = resolvePayProvider({ region: "auto", isChinaUser: true });
const [apiHealth, pbHealth, umami, uptime, ntfy, portalHealth, remoteConfig] =
await Promise.all([
client.health(),
probe(`${pb.publicUrl}/api/health`),
probe("https://umami.nomadro.cn"),
probe("https://uptimekuma.nomadro.cn"),
probe("https://ntfy.nomadro.cn/v1/health"),
probe(
`${(process.env.NOMADRO_PUBLIC_ORIGIN || "https://nomadro.cn").replace(/\/$/, "")}/api/health`,
),
readRemoteConfigFile(),
]);
const moduleSummary = Object.fromEntries(
Object.entries(remoteConfig.modules).map(([k, v]) => [
k,
{ enabled: v.enabled !== false, title: v.title },
]),
);
return NextResponse.json({
ok: true,
sdk: SDK_VERSION,
routes: PORTAL_ROUTES,
payHint: pay,
pb: { publicUrl: pb.publicUrl, serverUrl: pb.serverUrl },
health: {
payjsapi: apiHealth,
pocketbase: pbHealth,
umami,
uptimekuma: uptime,
ntfy,
portal: portalHealth,
},
remoteConfig: {
version: remoteConfig.version,
updatedAt: remoteConfig.updatedAt,
flags: remoteConfig.flags,
copy: {
vipPriceFen: remoteConfig.copy.vipPriceFen,
vipCta: remoteConfig.copy.vipCta,
homeBrand: remoteConfig.copy.homeBrand,
},
modules: moduleSummary,
},
verticals: [
{ id: "nav", name: "出海导航", href: "/nav", mini: ["weapp", "tt", "xhs"] },
{ id: "book", name: "电子书", href: "/book", admin: "/book/admin", mini: ["weapp", "tt", "xhs"] },
{ id: "community", name: "社群", href: "/community", mini: ["weapp", "tt", "xhs"] },
{ id: "vip", name: "私域会员", href: "/vip", mini: ["weapp"] },
],
});
}