Files
wireguard-ui/src/pages/admin/hosts/index.server.ts
T
2026-09-20 15:37:57 +01:00

41 lines
1023 B
TypeScript

import type {
BUN_SQLITE_WGUI_CLIENTS,
BUN_SQLITE_WGUI_HOSTS,
} from "@/db/types/db";
import type { PagePropsType, PageQueryObject, 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 clients_res = await BunSQLite.select<
BUN_SQLITE_WGUI_CLIENTS,
TableType
>({
table: "clients",
});
return {
props: {
hosts: hosts_res.payload || null,
clients: clients_res.payload || null,
},
};
};
export default server;