예제 소스
장기로 이해하는 규칙 엔진과 평가 함수 탐색 · 파일 59개
route.ts
import { NextRequest, NextResponse } from "next/server";
import { createGame, getLatestPlayingForGuest } from "@/lib/db";
export const runtime = "nodejs";
export async function GET(req: NextRequest) {
const guestId = req.nextUrl.searchParams.get("guestId")?.trim();
if (!guestId) {
return NextResponse.json({ error: "guestId required" }, { status: 400 });
}
const game = getLatestPlayingForGuest(guestId);
return NextResponse.json({ game });
}
export async function POST(req: NextRequest) {
const body = (await req.json().catch(() => ({}))) as {
guestId?: string;
cho_formation?: string;
han_formation?: string;
mode?: string;
ai_depth?: number;
ai_depth_han?: number;
bikjang?: boolean;
snapshot?: string;
};
const guestId = body.guestId?.trim();
if (!guestId) {
return NextResponse.json({ error: "guestId required" }, { status: 400 });
}
const game = createGame(guestId, {
cho_formation: body.cho_formation,
han_formation: body.han_formation,
mode: body.mode,
ai_depth: body.ai_depth,
ai_depth_han: body.ai_depth_han,
bikjang: body.bikjang,
snapshot: body.snapshot,
});
return NextResponse.json({ game });
}