diff --git a/.env b/.env new file mode 100644 index 0000000..f08502c --- /dev/null +++ b/.env @@ -0,0 +1,3 @@ +#This file current does nothing, but is here for future use. +URL=http://caddy.example.com +CADDY_API=http://192.168.1.69:2019 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 3102aa0..f066d55 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,8 @@ package-lock.json .DS_Store *.pem +.env + # debug npm-debug.log* yarn-debug.log* diff --git a/app/page.tsx b/app/page.tsx index 09326d0..98200e3 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -1,6 +1,3 @@ -"use client" - - import { useRoutes } from '@/lib/clientActions'; import Image from 'next/image'; import Loading from '@/components/Loading'; @@ -9,25 +6,20 @@ import { useState } from 'react'; import { RouteDialog } from '@/components/RouteDialog'; import Header from '@/components/Header'; import RouteCards from '@/components/RouteCards'; +import { SWRConfig } from 'swr'; export default function Home() { - const { data: routes, error, isLoading } = useRoutes(); - let routesMap: Route[] = routes as Route[]; - - if (error) return - if (isLoading) return - return (
- +
-
+
-
- +
+
) diff --git a/components/Error.tsx b/components/Error.tsx index 620c6cc..5e748f8 100644 --- a/components/Error.tsx +++ b/components/Error.tsx @@ -11,15 +11,17 @@ export default function Error() { return (
- - - Error - There was an error fetching your data - - - - - +
+ + + Error + There was an error fetching your data + + + + + +
) } \ No newline at end of file diff --git a/components/Header.tsx b/components/Header.tsx new file mode 100644 index 0000000..5530ea9 --- /dev/null +++ b/components/Header.tsx @@ -0,0 +1,68 @@ +"use client" + +import { CardTitle, Card, CardDescription, CardHeader, CardContent, CardFooter } from '@/components/ui/card'; +import RouteCards from '@/components/RouteCards'; +import { Button } from '@/components/ui/button'; +import { useState } from 'react'; +import { useRoutes } from '@/lib/clientActions'; +import Error from './Error'; +import Loading from './Loading'; +import { RouteDialog } from './RouteDialog'; + +export default function Header() { + + const { data: routes, error, isLoading } = useRoutes(); + let routesMap: Route[] = routes as Route[]; + + const [route, setRoute] = useState(); + const [open, setOpen] = useState(false); + + return ( + <> + {route && } + +
+ + + Active Routes + Amount of configured routes + + +
+

{routesMap?.length}

+
+
+ + + +
+
+ + + ) +} \ No newline at end of file diff --git a/components/Loading.tsx b/components/Loading.tsx index dce6e38..5a8c074 100644 --- a/components/Loading.tsx +++ b/components/Loading.tsx @@ -3,8 +3,10 @@ import Image from "next/image"; export default function Loading() { return (
- Loading -

Loading

+
+ Loading +

Loading

+
) } \ No newline at end of file diff --git a/components/RouteCards.tsx b/components/RouteCards.tsx index 18a04c8..b7f680c 100644 --- a/components/RouteCards.tsx +++ b/components/RouteCards.tsx @@ -2,18 +2,24 @@ import { Button } from '@/components/ui/button'; import { Card, CardHeader, CardTitle, CardDescription, CardContent, CardFooter } from "./ui/card"; -import { getHosts, getRouteUpstreams } from '@/lib/utils'; +import { getHandler, 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 { deleteRoute, useRoutes } from '@/lib/clientActions'; import { RouteDialog } from './RouteDialog'; +import Error from './Error'; +import Loading from './Loading'; -export default function RouteCards({ routes }: { routes: Route[] }) { +export default function RouteCards() { + + const { data: routes, error, isLoading } = useRoutes(); + let routesMap: Route[] = routes as Route[]; const [route, setRoute] = useState(); const [open, setOpen] = useState(false); + const { trigger: handleDelete } = useSWRMutation("/api/caddy/routes", deleteRoute, { onError: () => { return toast({ @@ -36,29 +42,44 @@ export default function RouteCards({ routes }: { routes: Route[] }) { setRoute(route); } + + if (error) return + if (isLoading) return + + return ( <> - {route && } + {route && } { - routes.map((route, index) => ( -
- + routesMap.map((route, index) => ( +
+ {getHosts(route)!.values().next().value} {getHosts(route)!.map((route => {route}))} -

- Tunneling to -

-

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

+
+
+

+ Type +

+

{getHandler(route)}

+
+
+

+ Tunneling to +

+

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

+
+
- + }}>Edit