mirror of
https://github.com/tale/headplane.git
synced 2026-08-11 06:16:52 +00:00
0512565f8e
Apparently I didn't use my brain cells and rely on the /version endpoint that Headscale has exposed since 0.26 (our lowest supported version). Switching to that significantly simplifies the API surface.
62 lines
1.3 KiB
TypeScript
62 lines
1.3 KiB
TypeScript
import { versions } from "node:process";
|
|
|
|
import { data } from "react-router";
|
|
|
|
import type { Route } from "./+types/info";
|
|
|
|
export async function loader({ request, context }: Route.LoaderArgs) {
|
|
if (context.config.server.info_secret == null) {
|
|
throw data(
|
|
{
|
|
status: "Forbidden",
|
|
},
|
|
403,
|
|
);
|
|
}
|
|
|
|
const bearer = request.headers.get("Authorization") ?? "";
|
|
if (!bearer.startsWith("Bearer ")) {
|
|
throw data(
|
|
{
|
|
status: "Unauthorized",
|
|
},
|
|
401,
|
|
);
|
|
}
|
|
|
|
const token = bearer.slice("Bearer ".length).trim();
|
|
if (token !== context.config.server.info_secret) {
|
|
throw data(
|
|
{
|
|
status: "Forbidden",
|
|
},
|
|
403,
|
|
);
|
|
}
|
|
|
|
// Use a fake API key for healthcheck
|
|
const api = context.headscale.client("fake-api-key");
|
|
const healthy = await api.isHealthy();
|
|
|
|
const body = {
|
|
status: healthy ? "healthy" : "unhealthy",
|
|
headplane_version: __VERSION__,
|
|
headscale_canonical_version: healthy ? context.headscale.version.raw : "unknown",
|
|
internal_versions: {
|
|
node: versions.node,
|
|
v8: versions.v8,
|
|
uv: versions.uv,
|
|
zlib: versions.zlib,
|
|
openssl: versions.openssl,
|
|
libc: versions.libc,
|
|
},
|
|
};
|
|
|
|
return new Response(JSON.stringify(body), {
|
|
status: 200,
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
});
|
|
}
|