This commit is contained in:
2025-12-27 02:05:19 +01:00
parent 0d7e7ce90c
commit ee29c6d9cb
3 changed files with 34 additions and 0 deletions
+2
View File
@@ -39,3 +39,5 @@ yarn-error.log*
# typescript # typescript
*.tsbuildinfo *.tsbuildinfo
next-env.d.ts next-env.d.ts
data
+21
View File
@@ -0,0 +1,21 @@
import { promises as fs } from "fs";
import path from "path";
export async function read<T extends object>(
template: T,
fp: string,
...filePaths: string[]
): Promise<T> {
const filePath = path.join(process.cwd(), fp, ...filePaths);
const dirPath = path.dirname(filePath);
try {
await fs.access(filePath);
} catch {
await fs.mkdir(dirPath, { recursive: true });
await fs.writeFile(filePath, JSON.stringify(template, null, 2), "utf-8");
}
const content = await fs.readFile(filePath, "utf-8");
return JSON.parse(content);
}
+11
View File
@@ -0,0 +1,11 @@
import { NextRequest, NextResponse } from "next/server";
import { version } from "../../../package.json";
import { read } from "./file";
import { randomUUID } from "crypto";
const TEMPLATE = { node_id: randomUUID() };
export async function GET(req: NextRequest): Promise<NextResponse> {
const { node_id } = await read(TEMPLATE, "data", "node.json");
return NextResponse.json({ app: "dockship", version, node_id });
}