1
0
Fork 0
polaris-task-force/src/app/api/arma/v1/heartbeat/route.ts
Z8MB1E fc3b961a43 feat(arma-bridge): add authenticated v1 bridge API routes
Add key-and-server-id authenticated endpoints for server heartbeat, event ingestion, and command pull/ack.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-08-23 18:51:33 -04:00

18 lines
1.1 KiB
TypeScript

import config from "@payload-config";
import { getPayload } from "payload";
import { NextRequest, NextResponse } from "next/server";
import { authenticateArmaBridge } from "@/lib/arma-bridge/auth";
export const runtime = "nodejs";
export const dynamic = "force-dynamic";
export async function POST(req: NextRequest) {
const serverId = authenticateArmaBridge(req);
if (serverId instanceof NextResponse) return serverId;
const body = await req.json().catch(() => ({}));
const payload = await getPayload({ config });
const found = await payload.find({ collection: "game-servers", where: { serverId: { equals: serverId } }, limit: 1, overrideAccess: true });
const data = { name: typeof body.name === "string" ? body.name : serverId, status: "online" as const, lastSeenAt: new Date().toISOString(), metadata: body.metadata ?? {} };
const server = found.docs[0] ? await payload.update({ collection: "game-servers", id: found.docs[0].id, data, overrideAccess: true }) : await payload.create({ collection: "game-servers", data: { serverId, ...data }, overrideAccess: true });
return NextResponse.json({ ok: true, serverId: server.id });
}