diff --git a/.gitignore b/.gitignore index fd3dbb5..3102aa0 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ /.pnp .pnp.js .yarn/install-state.gz - +package-lock.json # testing /coverage diff --git a/lib/utils.ts b/lib/utils.ts index 2a4d087..87cb5fc 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -1,8 +1,8 @@ import { type ClassValue, clsx } from "clsx" import { twMerge } from "tailwind-merge" - + export function cn(...inputs: ClassValue[]) { - return twMerge(clsx(inputs)) + return twMerge(clsx(inputs)); } export function getHosts(route: Route) { @@ -18,19 +18,37 @@ export function getRouteUpstreams(route: Route, index: number = 0) { return test; } -export async function getRoutes() { - const res = await fetch('http://192.168.1.69:2019/config/', { cache: 'no-store' }) +export async function getConfig() { + const res = await fetch('http://192.168.1.69:2019/config/', { cache: 'no-store' }); - if (!res.ok) { - throw new Error('Failed to fetch caddy config. Please check the network and try again.') - } + if (!res.ok) + throw new Error('Failed to fetch caddy config. Please check the network and try again.'); let caddyConfig: CaddyConfig = await res.json(); return caddyConfig; } -export async function removeRoute(route: Route) { - console.log(route) - const res = await fetch('http://192.168.1.69:2019/config/apps/http/servers/srv0/routes/') +export async function getRoutes(index: number = 0) { + const res = await fetch(`http://192.168.1.69:2019:config/apps/http/servers/srv${index}/routes/`, { cache: 'no-store' }); + + if(!res.ok) + throw new Error('Failed to fetch routes. Please check the network and try again.'); + + return res.json(); +} + +export async function removeRoute(route: Route, index: number = 0) { + console.log(route); + const res = await fetch(`http://192.168.1.69:2019/config/apps/http/servers/srv${index}/routes/`, { + method: 'DELETE', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(route) + }); + + if(!res.ok) throw new Error('Failed to remove route. Please check the network and try again.'); + + return res.json(); } \ No newline at end of file