@@ -54,7 +55,10 @@ export default function RouteCards({ routes }: { routes: Route[] }) {
{getRouteUpstreams(route)?.map((upstream => upstream.dial))}
-
+
diff --git a/components/RouteDialog.tsx b/components/RouteDialog.tsx
index e4d6f79..42ce5a3 100644
--- a/components/RouteDialog.tsx
+++ b/components/RouteDialog.tsx
@@ -5,17 +5,20 @@ import useSWRMutation from "swr/mutation";
import { toast } from "./ui/use-toast";
import { useFieldArray, useForm } from "react-hook-form";
import { get, set } from "lodash";
-import { Dialog, DialogContent } from "./ui/dialog";
+import { Dialog, DialogContent, DialogFooter } from "./ui/dialog";
import { Form, FormControl, FormField, FormItem, FormLabel } from "./ui/form";
import { Input } from "./ui/input";
import { Button } from "./ui/button";
import { DialogClose } from "@radix-ui/react-dialog";
+//TODO one day, I'll clean this up
export function RouteDialog({ route, routesMap, open, onOpenChange }: { route: Route, routesMap: Route[], open: boolean, onOpenChange: (open: boolean) => void }) {
let index = routesMap.indexOf(route);
const [modifiedRoute, setRoute] = useState(route);
+
+
const { trigger: pushUpdate } = useSWRMutation(`/api/caddy/routes`, updateRoute, {
onError: (err) => {
return toast({
@@ -33,12 +36,12 @@ export function RouteDialog({ route, routesMap, open, onOpenChange }: { route: R
}
});
- let validHosts: any[] = ["google.com", "test.com"];
- let validUpstreams: any[] = ["1.1.1.1", "69.126.24.175"];
+ let validHosts: any[] = [];
+ let validUpstreams: any[] = [];
let handler: string = "reverse_proxy";
if (index != -1) {
- validHosts = getHosts(route)!;
+ validHosts = getHosts(modifiedRoute)!;
validUpstreams = getRouteUpstreams(route).map((upstream) => upstream.dial);
handler = getHandler(route)!;
}
@@ -68,32 +71,8 @@ export function RouteDialog({ route, routesMap, open, onOpenChange }: { route: R
type: index == -1 ? 'PUT' : 'PATCH'
}
- update.route = {
- "handle": [
- {
- "handler": "subroute",
- "routes": [
- {
- "handle": [
- {
- "handler": "reverse_proxy",
- "upstreams": validUpstreams.map((upstream) => ({ "dial": upstream }))
- }
- ]
- }
- ]
- }
- ],
- "match": [
- {
- "host": validHosts
- }
- ],
- "terminal": true
- }
-
if (index == -1) update.index = routesMap.length - 1;
- console.log(update.index)
+ console.log(JSON.stringify(update.route), update.index)
pushUpdate(update);
})
@@ -133,7 +112,7 @@ export function RouteDialog({ route, routesMap, open, onOpenChange }: { route: R
Upstream {index + 1}
- handleChange(value, `handle[0].routes[0].handle[0].upstreams[${index}].dial`)} />
+ handleChange(value, `handle[0].routes[0].handle[0].upstreams[${index}].dial`)} />
)}
@@ -149,17 +128,17 @@ export function RouteDialog({ route, routesMap, open, onOpenChange }: { route: R
Host {index + 1}
- handleChange(value, `match[0].host[${index}]`)} />
+ handleChange(value, `match[0].host[${index}]`)} />
)}
/>
))}
-
-
+
+
+
+
+