Finished deleting
This commit is contained in:
parent
d60da0567a
commit
f0c9fd1182
2 changed files with 16 additions and 9 deletions
|
|
@ -3,7 +3,7 @@ import { NextApiRequest } from 'next';
|
|||
import { NextResponse } from 'next/server';
|
||||
|
||||
export async function GET() {
|
||||
let caddyConfig = await getConfig();
|
||||
let caddyConfig: CaddyConfig = await getConfig();
|
||||
|
||||
let routes: Array<Route> = [];
|
||||
|
||||
|
|
@ -22,11 +22,14 @@ export async function GET() {
|
|||
export async function DELETE(req: Request) {
|
||||
let route: Route = await req.json();
|
||||
let routes: Route[] = await getRoutes();
|
||||
let routesMap: Match[] = routes.map(r => r.match[0]);
|
||||
let routesMap: Route[] = routes.map(r => r);
|
||||
let hostsMap = routesMap.map(r => r.match[0].host);
|
||||
|
||||
let index = routesMap.findIndex((r) => (r.host === route.match[0].host))
|
||||
|
||||
if(index = -1) return new NextResponse(JSON.stringify({error: 'Route not found'}), {
|
||||
let targetRoute: Route = routesMap.filter((r) => (JSON.stringify(r.match[0]) === JSON.stringify(route.match[0]))).values().next().value;
|
||||
|
||||
let index = routesMap.indexOf(targetRoute);
|
||||
|
||||
if(index == -1) return new NextResponse(JSON.stringify({error: 'Route not found'}), {
|
||||
status: 404,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
|
@ -38,7 +41,7 @@ export async function DELETE(req: Request) {
|
|||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(route)
|
||||
body: JSON.stringify({route, error: false})
|
||||
});
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
'use server';
|
||||
|
||||
export async function getConfig() {
|
||||
const res = await fetch('http://192.168.1.69:2019/config/').catch(() => {
|
||||
const res = await fetch('http://192.168.1.69:2019/config/', {
|
||||
cache: 'no-cache',
|
||||
}).catch(() => {
|
||||
throw new Error('Failed to fetch caddy config. Please check the network and try again.');
|
||||
});
|
||||
|
||||
|
|
@ -25,12 +27,14 @@
|
|||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
cache: 'no-cache',
|
||||
body: JSON.stringify(route)
|
||||
|
||||
}).catch((e) => {
|
||||
console.log(e)
|
||||
throw new Error('Failed to remove route. Please check the network and try again.');
|
||||
});
|
||||
|
||||
|
||||
return res.json();
|
||||
}
|
||||
|
||||
|
|
@ -47,7 +51,7 @@
|
|||
}
|
||||
|
||||
export async function getRoutes() {
|
||||
let res = await fetch('http://localhost:3000/api/caddy/routes', { cache: 'no-cache'}).catch(() => {
|
||||
let res = await fetch('http://localhost:3000/api/caddy/routes', { cache: 'no-cache' }).catch(() => {
|
||||
throw new Error('Failed to fetch routes. Please check the network and try again.');
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue