Node Auth #4
This commit is contained in:
Generated
+7
@@ -18,6 +18,7 @@
|
||||
"class-variance-authority": "^0.7.1",
|
||||
"clsx": "^2.1.1",
|
||||
"dockerode": "^4.0.9",
|
||||
"http-status-codes": "^2.3.0",
|
||||
"js-cookie": "^3.0.5",
|
||||
"lucide-react": "^0.562.0",
|
||||
"next": "16.1.1",
|
||||
@@ -2732,6 +2733,12 @@
|
||||
"dev": true,
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/http-status-codes": {
|
||||
"version": "2.3.0",
|
||||
"resolved": "https://registry.npmjs.org/http-status-codes/-/http-status-codes-2.3.0.tgz",
|
||||
"integrity": "sha512-RJ8XvFvpPM/Dmc5SV+dC4y5PCeOhT3x1Hq0NU3rjGeg5a/CqlhZ7uudknPwZFz4aeAXDcbAyaeP7GAo9lvngtA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/ieee754": {
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz",
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
"class-variance-authority": "^0.7.1",
|
||||
"clsx": "^2.1.1",
|
||||
"dockerode": "^4.0.9",
|
||||
"http-status-codes": "^2.3.0",
|
||||
"js-cookie": "^3.0.5",
|
||||
"lucide-react": "^0.562.0",
|
||||
"next": "16.1.1",
|
||||
|
||||
@@ -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