fix(traefik): validate port 8080 before enabling dashboard

This commit is contained in:
HarikrishnanD
2025-11-13 11:52:06 +05:30
parent fd8f0e8f1f
commit c459997453
4 changed files with 93 additions and 4 deletions

View File

@@ -97,7 +97,12 @@ export const ShowTraefikActions = ({ serverId }: Props) => {
);
refetchDashboard();
})
.catch(() => {});
.catch((error) => {
const errorMessage =
error?.message ||
"Failed to toggle dashboard. Please check if port 8080 is available.";
toast.error(errorMessage);
});
}}
className="w-full cursor-pointer space-x-3"
>

View File

@@ -1,6 +1,7 @@
import {
canAccessToTraefikFiles,
checkGPUStatus,
checkPortInUse,
cleanStoppedContainers,
cleanUpDockerBuilder,
cleanUpSystemPrune,
@@ -130,6 +131,17 @@ export const settingsRouter = createTRPCRouter({
let newPorts = ports;
// If receive true, add 8080 to ports
if (input.enableDashboard) {
// Check if port 8080 is already in use before enabling dashboard
const portCheck = await checkPortInUse(8080, input.serverId);
if (portCheck.isInUse) {
const conflictingContainer = portCheck.conflictingContainer
? ` by container "${portCheck.conflictingContainer}"`
: "";
throw new TRPCError({
code: "CONFLICT",
message: `Port 8080 is already in use${conflictingContainer}. Please stop the conflicting service or use a different port for the Traefik dashboard.`,
});
}
newPorts.push({
targetPort: 8080,
publishedPort: 8080,