Started working on route removal
This commit is contained in:
parent
57f6a5c309
commit
f8c49b1bc5
4 changed files with 48 additions and 13 deletions
|
|
@ -19,9 +19,7 @@ export async function POST(req: Request) {
|
|||
let routeUpstreams: Upstream[] = getRouteUpstreams(route);
|
||||
|
||||
let upstreamsRequested: UpstreamRequest[] = upstreams.filter(upstream => {
|
||||
return routeUpstreams.find(routeUpstream => {
|
||||
return routeUpstream.dial === upstream.address;
|
||||
});
|
||||
return routeUpstreams.find(routeUpstream => routeUpstream.dial === upstream.address);
|
||||
});
|
||||
|
||||
return new NextResponse(JSON.stringify(upstreamsRequested), {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { getConfig } from '@/lib/utils';
|
||||
import { getConfig, getServer } from '@/lib/utils';
|
||||
import { NextApiRequest } from 'next';
|
||||
import { NextResponse } from 'next/server';
|
||||
|
||||
|
|
@ -19,6 +19,29 @@ export async function GET() {
|
|||
}
|
||||
|
||||
export async function DELETE(req: Request) {
|
||||
|
||||
let route: Route = await req.json();
|
||||
let routes: Server[] = await getServer();
|
||||
|
||||
let indexOfRoute = routes.findIndex((routeToFind: Route) => route.handle == routeToFind.handle);
|
||||
|
||||
console.log(indexOfRoute)
|
||||
|
||||
return new NextResponse(JSON.stringify("Test"), {
|
||||
status: 200,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
const res = await fetch(`http://192.168.1.69:2019/config/apps/http/servers/srv0/routes/${index}`, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(route)
|
||||
});
|
||||
|
||||
return new NextResponse(JSON.stringify("Test"), {
|
||||
status: 200,
|
||||
headers: {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
"use client"
|
||||
|
||||
import { getHosts, getRouteUpstreams, getUpstreamRequests } from "@/lib/utils";
|
||||
import { deleteRoute, getHosts, getRouteUpstreams, getUpstreamRequests } from "@/lib/utils";
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card, CardHeader, CardTitle, CardDescription, CardContent, CardFooter } from "./ui/card";
|
||||
|
||||
export default function RouteCards({ routes }: { routes: Array<Route> }) {
|
||||
|
||||
let handleClick = (route: Route) => {
|
||||
console.log(JSON.stringify(route))
|
||||
deleteRoute(route);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -28,7 +28,7 @@ export default function RouteCards({ routes }: { routes: Array<Route> }) {
|
|||
</CardContent>
|
||||
<CardFooter className="flex justify-between">
|
||||
<Button onClick={() => {handleClick(route)}}>Edit</Button>
|
||||
<Button variant="destructive" onClick={() => {handleClick(route)}}>Edit</Button>
|
||||
<Button variant="destructive" onClick={() => {handleClick(route)}}>Delete</Button>
|
||||
</CardFooter>
|
||||
</Card>
|
||||
</div>
|
||||
|
|
|
|||
20
lib/utils.ts
20
lib/utils.ts
|
|
@ -29,9 +29,23 @@ export async function getConfig() {
|
|||
return caddyConfig;
|
||||
}
|
||||
|
||||
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/`, {
|
||||
export async function getServer() {
|
||||
const res = await fetch('http://localhost:3000/api/caddy/servers', { cache: 'no-store' });
|
||||
|
||||
if (!res.ok)
|
||||
throw new Error('Failed to fetch caddy config. Please check the network and try again.');
|
||||
|
||||
let server: Server = await res.json();
|
||||
return server;
|
||||
}
|
||||
|
||||
export async function deleteRoute(route: Route, index: number = 0) {
|
||||
let server: Server = await getServer();
|
||||
|
||||
console.log(server)
|
||||
return true;
|
||||
|
||||
const res = await fetch(`http://192.168.1.69:2019/config/apps/http/servers/srv${index}/routes/${index}`, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue