Cleaned up utils and added new options for getting more caddy info

This commit is contained in:
brian 2023-11-14 23:17:34 -05:00
parent b99e1bc6f6
commit 096dac9903
2 changed files with 29 additions and 11 deletions

2
.gitignore vendored
View file

@ -5,7 +5,7 @@
/.pnp /.pnp
.pnp.js .pnp.js
.yarn/install-state.gz .yarn/install-state.gz
package-lock.json
# testing # testing
/coverage /coverage

View file

@ -2,7 +2,7 @@ import { type ClassValue, clsx } from "clsx"
import { twMerge } from "tailwind-merge" import { twMerge } from "tailwind-merge"
export function cn(...inputs: ClassValue[]) { export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs)) return twMerge(clsx(inputs));
} }
export function getHosts(route: Route) { export function getHosts(route: Route) {
@ -18,19 +18,37 @@ export function getRouteUpstreams(route: Route, index: number = 0) {
return test; return test;
} }
export async function getRoutes() { export async function getConfig() {
const res = await fetch('http://192.168.1.69:2019/config/', { cache: 'no-store' }) const res = await fetch('http://192.168.1.69:2019/config/', { cache: 'no-store' });
if (!res.ok) { if (!res.ok)
throw new Error('Failed to fetch caddy config. Please check the network and try again.') throw new Error('Failed to fetch caddy config. Please check the network and try again.');
}
let caddyConfig: CaddyConfig = await res.json(); let caddyConfig: CaddyConfig = await res.json();
return caddyConfig; return caddyConfig;
} }
export async function removeRoute(route: Route) { export async function getRoutes(index: number = 0) {
console.log(route) const res = await fetch(`http://192.168.1.69:2019:config/apps/http/servers/srv${index}/routes/`, { cache: 'no-store' });
const res = await fetch('http://192.168.1.69:2019/config/apps/http/servers/srv0/routes/')
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();
} }