Node Auth #4
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
import { read } from "@/app/api/file";
|
||||
import { NodeJsonTemplate } from "@/app/api/types";
|
||||
import { NextRequest } from "next/server";
|
||||
|
||||
export default async function testAuth(
|
||||
req: NextRequest
|
||||
): Promise<null | string> {
|
||||
const auth = req.headers.get("Authorization")?.replaceAll("ApiKey", "");
|
||||
|
||||
if (!auth)
|
||||
return "Missing Authorization header (Authorization: ApiKey <key>)";
|
||||
|
||||
const { key } = await read(NodeJsonTemplate, "data", "node.json");
|
||||
|
||||
if (key !== auth) return "Invalid key";
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { version } from "@/../package.json";
|
||||
import testAuth from "../auth";
|
||||
import { StatusCodes } from "http-status-codes";
|
||||
|
||||
export async function GET(req: NextRequest): Promise<NextResponse> {
|
||||
const auth = testAuth(req);
|
||||
|
||||
if (auth) {
|
||||
return NextResponse.json(
|
||||
{ message: auth },
|
||||
{ status: StatusCodes.UNAUTHORIZED }
|
||||
);
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
message: "ok",
|
||||
app: "dockship",
|
||||
version,
|
||||
});
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { version } from "../../../package.json";
|
||||
import { read } from "./file";
|
||||
import { NodeJsonTemplate } from "./types";
|
||||
import { version } from "@/../package.json";
|
||||
import { read } from "@/app/api/file";
|
||||
import { NodeJsonTemplate } from "@/app/api/types";
|
||||
|
||||
export async function GET(req: NextRequest): Promise<NextResponse> {
|
||||
const { node_id } = await read(NodeJsonTemplate, "data", "node.json");
|
||||
|
||||
Reference in New Issue
Block a user