Update routes
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import type { BUN_SQLITE_WGUI_HOSTS } from "@/db/types/db";
|
||||
import { AppData } from "@/src/data/app-data";
|
||||
import type { PagePropsType, TableType } from "@/src/types";
|
||||
import BunSQLite from "@moduletrace/bun-sqlite";
|
||||
import type { BunextPageServerFn } from "@moduletrace/bunext/types";
|
||||
|
||||
const server: BunextPageServerFn<PagePropsType> = async (ctx) => {
|
||||
const props = ctx.props as PagePropsType;
|
||||
|
||||
if (!props.main_host?.name) {
|
||||
return {
|
||||
redirect: {
|
||||
destination: `/admin/hosts/add`,
|
||||
permanent: false,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const hosts_res = await BunSQLite.select<BUN_SQLITE_WGUI_HOSTS, TableType>({
|
||||
table: "hosts",
|
||||
});
|
||||
|
||||
const hosts = hosts_res.payload || [];
|
||||
|
||||
const requested_id = Number(ctx.url.searchParams.get("host_id"));
|
||||
|
||||
const host =
|
||||
hosts.find((h) => Number(h.id) === requested_id) ||
|
||||
hosts.find((h) => Number(h.id) === AppData["WireguardMainHostID"]) ||
|
||||
hosts[0] ||
|
||||
null;
|
||||
|
||||
return {
|
||||
props: {
|
||||
hosts,
|
||||
host,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export default server;
|
||||
@@ -0,0 +1,25 @@
|
||||
import type { BunextPageModuleMeta } from "@moduletrace/bunext/types";
|
||||
import PageHeader from "@/src/components/general/page-header";
|
||||
import PageBody from "@/src/components/general/page-body";
|
||||
import { SiteData } from "@/src/data/site-data";
|
||||
import ClientRouteForm from "@/src/components/general/client-route-form";
|
||||
|
||||
export default function AddClientPage() {
|
||||
return (
|
||||
<>
|
||||
<PageHeader
|
||||
title="Add Route"
|
||||
description="Add a Client Route"
|
||||
back={{ href: "/admin/routes", title: "Routes" }}
|
||||
/>
|
||||
<PageBody>
|
||||
<ClientRouteForm />
|
||||
</PageBody>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export const meta: BunextPageModuleMeta = {
|
||||
title: `Add client route | ${SiteData["SiteName"]}`,
|
||||
description: `Add a Caddy route config to a Wireguard host`,
|
||||
};
|
||||
@@ -3,6 +3,7 @@ import PageHeader from "@/src/components/general/page-header";
|
||||
import PageBody from "@/src/components/general/page-body";
|
||||
import ClientRoutesPanel from "@/src/components/general/client-routes-panel";
|
||||
import { SiteData } from "@/src/data/site-data";
|
||||
import { Plus } from "lucide-react";
|
||||
|
||||
export default function RoutesPage() {
|
||||
return (
|
||||
@@ -10,6 +11,12 @@ export default function RoutesPage() {
|
||||
<PageHeader
|
||||
title="Routes"
|
||||
description="HTTPS services exposed to WireGuard clients, with their host and certificate status."
|
||||
primary_action={{
|
||||
key: "add-client-route",
|
||||
title: "Add Route",
|
||||
href: "/admin/routes/add",
|
||||
icon: <Plus size={14} />,
|
||||
}}
|
||||
/>
|
||||
<PageBody>
|
||||
<ClientRoutesPanel
|
||||
|
||||
Reference in New Issue
Block a user