mirror of
https://github.com/tale/headplane.git
synced 2026-08-31 01:09:25 +00:00
feat: switch to a central singleton handler
This also adds support for Headscale TLS installations
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
import { LoaderFunctionArgs } from 'react-router';
|
||||
import type { AppContext } from '~server/context/app';
|
||||
import { hp_getSingleton, hp_getSingletonUnsafe } from '~server/context/global';
|
||||
|
||||
export async function loader({
|
||||
request,
|
||||
context,
|
||||
}: LoaderFunctionArgs<AppContext>) {
|
||||
if (!context?.agentData) {
|
||||
export async function loader({ request }: LoaderFunctionArgs) {
|
||||
const data = hp_getSingletonUnsafe('ws_agent_data');
|
||||
|
||||
if (!data) {
|
||||
return new Response(JSON.stringify({ error: 'Agent data unavailable' }), {
|
||||
status: 400,
|
||||
headers: {
|
||||
@@ -25,13 +24,14 @@ export async function loader({
|
||||
});
|
||||
}
|
||||
|
||||
const entries = context.agentData.toJSON();
|
||||
const entries = data.toJSON();
|
||||
const missing = nodeIds.filter((nodeID) => !entries[nodeID]);
|
||||
if (missing.length > 0) {
|
||||
await context.hp_agentRequest(missing);
|
||||
const requestCall = hp_getSingleton('ws_fetch_data');
|
||||
requestCall(missing);
|
||||
}
|
||||
|
||||
return new Response(JSON.stringify(context.agentData), {
|
||||
return new Response(JSON.stringify(data), {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user