Files
cruciverba_1/webapp/app/api/crosswords/[id]/route.ts

19 lines
555 B
TypeScript

import { readFile } from "node:fs/promises";
import { join } from "node:path";
import { NextResponse } from "next/server";
const RUNTIME_DIR = join(process.cwd(), ".runtime-crosswords");
export async function GET(
_request: Request,
context: { params: Promise<{ id: string }> },
) {
try {
const { id } = await context.params;
const source = await readFile(join(RUNTIME_DIR, `${id}.json`), "utf-8");
return NextResponse.json(JSON.parse(source));
} catch {
return NextResponse.json({ status: "not_found" }, { status: 404 });
}
}