Skip to content

Commit

Permalink
fix(traefik): allow to save domain without letsencrypt email when the…
Browse files Browse the repository at this point in the history
… cert is none Dokploy#542
  • Loading branch information
Siumauricio committed Oct 12, 2024
1 parent 3396974 commit 8036455
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
21 changes: 16 additions & 5 deletions apps/dokploy/components/dashboard/settings/web-domain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,22 @@ import { useForm } from "react-hook-form";
import { toast } from "sonner";
import { z } from "zod";

const addServerDomain = z.object({
domain: z.string().min(1, { message: "URL is required" }),
letsEncryptEmail: z.string().min(1, "Email is required").email(),
certificateType: z.enum(["letsencrypt", "none"]),
});
const addServerDomain = z
.object({
domain: z.string().min(1, { message: "URL is required" }),
letsEncryptEmail: z.string(),
certificateType: z.enum(["letsencrypt", "none"]),
})
.superRefine((data, ctx) => {
if (data.certificateType === "letsencrypt" && !data.letsEncryptEmail) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message:
"LetsEncrypt email is required when certificate type is letsencrypt",
path: ["letsEncryptEmail"],
});
}
});

type AddServerDomain = z.infer<typeof addServerDomain>;

Expand Down
9 changes: 7 additions & 2 deletions apps/dokploy/server/api/routers/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ export const settingsRouter = createTRPCRouter({
}
const admin = await updateAdmin(ctx.user.authId, {
host: input.host,
letsEncryptEmail: input.letsEncryptEmail,
...(input.letsEncryptEmail && {
letsEncryptEmail: input.letsEncryptEmail,
}),
certificateType: input.certificateType,
});

Expand All @@ -186,7 +188,10 @@ export const settingsRouter = createTRPCRouter({
}

updateServerTraefik(admin, input.host);
updateLetsEncryptEmail(admin.letsEncryptEmail);
if (input.letsEncryptEmail) {
updateLetsEncryptEmail(input.letsEncryptEmail);
}

return admin;
}),
cleanSSHPrivateKey: adminProcedure.mutation(async ({ ctx }) => {
Expand Down
8 changes: 6 additions & 2 deletions packages/server/src/db/schema/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const createSchema = createInsertSchema(admins, {
sshPrivateKey: z.string().optional(),
certificateType: z.enum(["letsencrypt", "none"]).default("none"),
serverIp: z.string().optional(),
letsEncryptEmail: z.string().optional(),
});

export const apiSaveSSHKey = createSchema
Expand All @@ -55,11 +56,14 @@ export const apiSaveSSHKey = createSchema

export const apiAssignDomain = createSchema
.pick({
letsEncryptEmail: true,
host: true,
certificateType: true,
letsEncryptEmail: true,
})
.required();
.required()
.partial({
letsEncryptEmail: true,
});

export const apiUpdateDockerCleanup = createSchema
.pick({
Expand Down

0 comments on commit 8036455

Please sign in to comment.