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>
37 lines
968 B
TypeScript
37 lines
968 B
TypeScript
import { NextResponse } from "next/server";
|
||
import {
|
||
ADMIN_COOKIE,
|
||
isAdminConfigured,
|
||
mintAdminSession,
|
||
verifyAdminPassword,
|
||
} from "~/lib/admin-auth";
|
||
|
||
export async function POST(request: Request) {
|
||
if (!isAdminConfigured()) {
|
||
return NextResponse.json(
|
||
{
|
||
ok: false,
|
||
error: "未配置 NOMADRO_ADMIN_PASSWORD,请在 .env.local 设置后再登录",
|
||
},
|
||
{ status: 503 },
|
||
);
|
||
}
|
||
|
||
const body = (await request.json().catch(() => ({}))) as { password?: string };
|
||
const password = String(body.password || "");
|
||
if (!verifyAdminPassword(password)) {
|
||
return NextResponse.json({ ok: false, error: "密码错误" }, { status: 401 });
|
||
}
|
||
|
||
const token = mintAdminSession();
|
||
const res = NextResponse.json({ ok: true });
|
||
res.cookies.set(ADMIN_COOKIE, token, {
|
||
httpOnly: true,
|
||
sameSite: "lax",
|
||
secure: process.env.NODE_ENV === "production",
|
||
path: "/",
|
||
maxAge: 60 * 60 * 12,
|
||
});
|
||
return res;
|
||
}
|