feat: switch to a central singleton handler
This also adds support for Headscale TLS installations
This commit is contained in:
parent
43e06987ad
commit
6108de52e7
35 changed files with 339 additions and 399 deletions
|
|
@ -1,8 +1,8 @@
|
|||
import type { ActionFunctionArgs } from 'react-router';
|
||||
import { del, post } from '~/utils/headscale';
|
||||
import log from '~/utils/log';
|
||||
import { send } from '~/utils/res';
|
||||
import { getSession } from '~/utils/sessions.server';
|
||||
import log from '~server/utils/log';
|
||||
|
||||
export async function menuAction(request: ActionFunctionArgs['request']) {
|
||||
const session = await getSession(request.headers.get('Cookie'));
|
||||
|
|
|
|||
|
|
@ -14,16 +14,12 @@ import cn from '~/utils/cn';
|
|||
import { hs_getConfig } from '~/utils/config/loader';
|
||||
import { pull } from '~/utils/headscale';
|
||||
import { getSession } from '~/utils/sessions.server';
|
||||
import type { AppContext } from '~server/context/app';
|
||||
import { hp_getSingleton } from '~server/context/global';
|
||||
import { menuAction } from './action';
|
||||
import MenuOptions from './components/menu';
|
||||
import Routes from './dialogs/routes';
|
||||
|
||||
export async function loader({
|
||||
request,
|
||||
params,
|
||||
context,
|
||||
}: LoaderFunctionArgs<AppContext>) {
|
||||
export async function loader({ request, params }: LoaderFunctionArgs) {
|
||||
const session = await getSession(request.headers.get('Cookie'));
|
||||
if (!params.id) {
|
||||
throw new Error('No machine ID provided');
|
||||
|
|
@ -49,7 +45,7 @@ export async function loader({
|
|||
routes: routes.routes.filter((route) => route.node.id === params.id),
|
||||
users: users.users,
|
||||
magic,
|
||||
agent: context?.agents.includes(machine.node.id),
|
||||
agent: [...hp_getSingleton('ws_agents').keys()].includes(machine.node.id),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -61,7 +57,6 @@ export default function Page() {
|
|||
const { machine, magic, routes, users, agent } =
|
||||
useLoaderData<typeof loader>();
|
||||
const [showRouting, setShowRouting] = useState(false);
|
||||
console.log(machine.expiry);
|
||||
|
||||
const expired =
|
||||
machine.expiry === '0001-01-01 00:00:00' ||
|
||||
|
|
|
|||
|
|
@ -12,17 +12,13 @@ import { getSession } from '~/utils/sessions.server';
|
|||
|
||||
import Tooltip from '~/components/Tooltip';
|
||||
import { hs_getConfig } from '~/utils/config/loader';
|
||||
import { noContext } from '~/utils/log';
|
||||
import useAgent from '~/utils/useAgent';
|
||||
import { AppContext } from '~server/context/app';
|
||||
import { hp_getConfig, hp_getSingleton } from '~server/context/global';
|
||||
import { menuAction } from './action';
|
||||
import MachineRow from './components/machine';
|
||||
import NewMachine from './dialogs/new';
|
||||
|
||||
export async function loader({
|
||||
request,
|
||||
context,
|
||||
}: LoaderFunctionArgs<AppContext>) {
|
||||
export async function loader({ request }: LoaderFunctionArgs) {
|
||||
const session = await getSession(request.headers.get('Cookie'));
|
||||
const [machines, routes, users] = await Promise.all([
|
||||
pull<{ nodes: Machine[] }>('v1/node', session.get('hsApiKey')!),
|
||||
|
|
@ -30,11 +26,7 @@ export async function loader({
|
|||
pull<{ users: User[] }>('v1/user', session.get('hsApiKey')!),
|
||||
]);
|
||||
|
||||
if (!context) {
|
||||
throw noContext();
|
||||
}
|
||||
|
||||
const ctx = context.context;
|
||||
const context = hp_getConfig();
|
||||
const { mode, config } = hs_getConfig();
|
||||
let magic: string | undefined;
|
||||
|
||||
|
|
@ -49,9 +41,9 @@ export async function loader({
|
|||
routes: routes.routes,
|
||||
users: users.users,
|
||||
magic,
|
||||
server: ctx.headscale.url,
|
||||
publicServer: ctx.headscale.public_url,
|
||||
agents: context.agents,
|
||||
server: context.headscale.url,
|
||||
publicServer: context.headscale.public_url,
|
||||
agents: [...hp_getSingleton('ws_agents').keys()],
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue