Node Key #4
This commit is contained in:
+1
-1
@@ -2,7 +2,7 @@ import { promises as fs } from "fs";
|
|||||||
import path from "path";
|
import path from "path";
|
||||||
|
|
||||||
export async function read<T extends object>(
|
export async function read<T extends object>(
|
||||||
template: T,
|
template: () => T,
|
||||||
fp: string,
|
fp: string,
|
||||||
...filePaths: string[]
|
...filePaths: string[]
|
||||||
): Promise<T> {
|
): Promise<T> {
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
import { NextRequest, NextResponse } from "next/server";
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
import { version } from "../../../package.json";
|
import { version } from "../../../package.json";
|
||||||
import { read } from "./file";
|
import { read } from "./file";
|
||||||
import { randomUUID } from "crypto";
|
import { NodeJsonTemplate } from "./types";
|
||||||
|
|
||||||
const TEMPLATE = { node_id: randomUUID() };
|
|
||||||
|
|
||||||
export async function GET(req: NextRequest): Promise<NextResponse> {
|
export async function GET(req: NextRequest): Promise<NextResponse> {
|
||||||
const { node_id } = await read(TEMPLATE, "data", "node.json");
|
const { node_id } = await read(NodeJsonTemplate, "data", "node.json");
|
||||||
|
|
||||||
return NextResponse.json({ app: "dockship", version, node_id });
|
return NextResponse.json({ app: "dockship", version, node_id });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import { randomBytes, randomUUID } from "crypto";
|
||||||
|
|
||||||
|
export interface NodeJson {
|
||||||
|
node_id: string;
|
||||||
|
key: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const NodeJsonTemplate: () => NodeJson = () => ({
|
||||||
|
node_id: randomUUID(),
|
||||||
|
key: randomBytes(20).toString("base64"),
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user