diff --git a/components/dashboard/settings/web-server.tsx b/components/dashboard/settings/web-server.tsx index 61c4917f..732570cc 100644 --- a/components/dashboard/settings/web-server.tsx +++ b/components/dashboard/settings/web-server.tsx @@ -8,7 +8,7 @@ import { } from "@/components/ui/card"; import { Label } from "@/components/ui/label"; import { Switch } from "@/components/ui/switch"; -import React, { useEffect, useState } from "react"; +import React from "react"; import { DropdownMenu, @@ -37,6 +37,9 @@ export const WebServer = () => { api.settings.reloadTraefik.useMutation(); const { mutateAsync: cleanAll, isLoading: cleanAllIsLoading } = api.settings.cleanAll.useMutation(); + const { mutateAsync: toggleDashboard, isLoading: toggleDashboardIsLoading } = + api.settings.toggleDashboard.useMutation(); + const { mutateAsync: cleanDockerBuilder, isLoading: cleanDockerBuilderIsLoading, @@ -107,6 +110,7 @@ export const WebServer = () => { View Traefik config + e.preventDefault()} @@ -124,8 +128,14 @@ export const WebServer = () => { - - @@ -157,6 +167,38 @@ export const WebServer = () => { View Traefik config + { + await toggleDashboard({ + enableDashboard: true, + }) + .then(async () => { + toast.success("Dashboard Enabled"); + }) + .catch(() => { + toast.error("Error to enable Dashboard"); + }); + }} + className="w-full cursor-pointer space-x-3" + > + Enable Dashboard + + { + await toggleDashboard({ + enableDashboard: false, + }) + .then(async () => { + toast.success("Dashboard Disabled"); + }) + .catch(() => { + toast.error("Error to disable Dashboard"); + }); + }} + className="w-full cursor-pointer space-x-3" + > + Disable Dashboard + { + await initializeTraefik(input.enableDashboard); + return true; + }), + cleanUnusedImages: adminProcedure.mutation(async () => { await cleanUpUnusedImages(); return true; diff --git a/server/db/schema/admin.ts b/server/db/schema/admin.ts index f394bb4e..d40da902 100644 --- a/server/db/schema/admin.ts +++ b/server/db/schema/admin.ts @@ -93,3 +93,7 @@ export const apiModifyTraefikConfig = z.object({ export const apiReadTraefikConfig = z.object({ path: z.string().min(1), }); + +export const apiEnableDashboard = z.object({ + enableDashboard: z.boolean().optional(), +}); diff --git a/server/setup/traefik-setup.ts b/server/setup/traefik-setup.ts index e9f27860..f36d982a 100644 --- a/server/setup/traefik-setup.ts +++ b/server/setup/traefik-setup.ts @@ -11,7 +11,7 @@ const TRAEFIK_SSL_PORT = Number.parseInt(process.env.TRAEFIK_SSL_PORT ?? "", 10) || 443; const TRAEFIK_PORT = Number.parseInt(process.env.TRAEFIK_PORT ?? "", 10) || 80; -export const initializeTraefik = async () => { +export const initializeTraefik = async (enableDashboard = false) => { const imageName = "traefik:v2.5"; const containerName = "dokploy-traefik"; const settings: CreateServiceOptions = { @@ -59,11 +59,15 @@ export const initializeTraefik = async () => { PublishedPort: TRAEFIK_PORT, PublishMode: "host", }, - { - TargetPort: 8080, - PublishedPort: 8080, - PublishMode: "host", - }, + ...(enableDashboard + ? [ + { + TargetPort: 8080, + PublishedPort: 8080, + PublishMode: "host" as const, + }, + ] + : []), ], }, };