"use client" import { Button } from '@/components/ui/button'; import { Card, CardHeader, CardTitle, CardDescription, CardContent, CardFooter } from "./ui/card"; import { getHosts, getRouteUpstreams } from '@/lib/utils'; import { toast } from './ui/use-toast'; import React, { useState } from 'react'; import useSWRMutation from 'swr/mutation'; import { deleteRoute } from '@/lib/clientActions'; import { Dialog, DialogContent, DialogHeader } from './ui/dialog'; import { DialogDescription, DialogTitle } from '@radix-ui/react-dialog'; import { Form, FormControl, FormField, FormItem, FormLabel } from './ui/form'; import { useForm } from 'react-hook-form'; import { Input } from './ui/input'; export default function RouteCards({ routes }: { routes: Route[] }) { const [route, setRoute] = useState(); const { trigger: handleDelete } = useSWRMutation("/api/caddy/routes", deleteRoute, { onError: () => { return toast({ title: "Error", description: "There was an error deleting the route", variant: "destructive" }); }, onSuccess: () => { toast({ title: "Success", description: "Route deleted successfully!", variant: "success" }); } }); let editRoute = (route: Route) => { setRoute(route); } return ( <> { routes.map((route, index) => (
{getHosts(route).values().next().value} {getHosts(route).map((route => {route}))}

Tunneling to

{getRouteUpstreams(route)?.map((upstream => upstream.dial))}

))} ) } export function EditRouteDialog({ route }: { route?: Route }) { const form = useForm({ defaultValues: { handler: route?.handle[0].handler, upstreams: route?.handle[0].upstreams, //hosts: route?.match[0].host, } }); let test: RouteHandle = { handle: [ { handler: 'subroutes', routes: [ { handle: [ { handler: 'reverse_proxy', upstreams: [ { dial: 'localhost:8080' } ] } ] } ] } ], match: [ { host: [ 'example.com' ] } ] } let onSubmit = ((data: any) => { console.log('Original Route', JSON.stringify(route)) console.log(data) }) return (
( Handler )} > {route ? getRouteUpstreams(route)?.map((upstream, index) => ( ( Upstream {index + 1} )} > )) : <>} {route ? getHosts(route)?.map((host, index) => ( ( Host {index + 1} )} > )) : <>}
) }