Node Auth fix and simple usage test

This commit is contained in:
2025-12-27 02:48:32 +01:00
parent 38c2c9fb6d
commit d92b92450f
7 changed files with 323 additions and 17 deletions
+4 -1
View File
@@ -5,7 +5,10 @@ import { NextRequest } from "next/server";
export default async function testAuth(
req: NextRequest
): Promise<null | string> {
const auth = req.headers.get("Authorization")?.replaceAll("ApiKey", "");
const auth = req.headers
.get("Authorization")
?.replaceAll("ApiKey", "")
.trim();
if (!auth)
return "Missing Authorization header (Authorization: ApiKey <key>)";
+19
View File
@@ -0,0 +1,19 @@
import { NextRequest, NextResponse } from "next/server";
import testAuth from "../auth";
import { StatusCodes } from "http-status-codes";
export async function GET(req: NextRequest): Promise<NextResponse> {
const auth = await testAuth(req);
if (auth) {
return NextResponse.json(
{ message: auth },
{ status: StatusCodes.UNAUTHORIZED }
);
}
return NextResponse.json({
message: "ok",
containers: [],
});
}
+2 -13
View File
@@ -1,15 +1,6 @@
"use client";
import { useEffect } from "react";
const NotFound = () => {
useEffect(() => {
console.error(
"404 Error: User attempted to access non-existent route:",
location.pathname
);
}, [location.pathname]);
export default function NotFound() {
return (
<div className="flex min-h-screen items-center justify-center bg-muted">
<div className="text-center">
@@ -23,6 +14,4 @@ const NotFound = () => {
</div>
</div>
);
};
export default NotFound;
}
+3 -3
View File
@@ -1,13 +1,13 @@
"use client";
import { getDocker } from "@/core/docker";
import { getDocker } from "@/core/client/docker";
export default function Home() {
return (
<div>
<button
onClick={() => {
getDocker();
onClick={async () => {
console.log(await getDocker("localhost", "oD7tMrnkxIvuFrR+b6QZh66E4PU="));
}}
>
Get docker
+14
View File
@@ -0,0 +1,14 @@
"use server";
import axios from "axios";
export async function getDocker(
node_ip: string,
key: string
): Promise<{ version: string }> {
return await (
await axios.get(`http://${node_ip}:3000/api/get-docker`, {
headers: { Authorization: `ApiKey ${key}` },
})
).data;
}