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>
10 lines
632 B
TypeScript
10 lines
632 B
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
|
|
export function authenticateArmaBridge(req: NextRequest): string | NextResponse {
|
|
const secret = process.env.ARMA_BRIDGE_API_KEY;
|
|
if (!secret) return NextResponse.json({ error: "Arma bridge is not configured." }, { status: 503 });
|
|
if (req.headers.get("x-arma-bridge-key") !== secret) return NextResponse.json({ error: "Unauthorized." }, { status: 401 });
|
|
const serverId = req.headers.get("x-arma-server-id");
|
|
if (!serverId || !/^[a-zA-Z0-9_-]{3,64}$/.test(serverId)) return NextResponse.json({ error: "Invalid server id." }, { status: 400 });
|
|
return serverId;
|
|
}
|