Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,16 @@ export const AddDomain = ({ id, type, domainId = "", children }: Props) => {
serverId: application?.serverId || "",
});

const { data: certificateResolvers } =
api.domain.certificateResolvers.useQuery(
{
serverId: application?.serverId || undefined,
},
{
enabled: isOpen,
},
);

const {
data: services,
isFetching: isLoadingServices,
Expand Down Expand Up @@ -228,12 +238,23 @@ export const AddDomain = ({ id, type, domainId = "", children }: Props) => {
});

const certificateType = form.watch("certificateType");
const customCertResolver = form.watch("customCertResolver");
const useCustomEntrypoint = form.watch("useCustomEntrypoint");
const https = form.watch("https");
const domainType = form.watch("domainType");
const host = form.watch("host");
const isTraefikMeDomain = host?.includes("sslip.io") || false;

// Synthetic value for the certificate provider Select: detected resolvers
// from traefik.yml are stored as certificateType="custom" +
// customCertResolver=<name>, but displayed as their own option.
const certSelectValue =
certificateType === "custom" &&
customCertResolver &&
certificateResolvers?.includes(customCertResolver)
? `resolver:${customCertResolver}`
: (certificateType ?? "");

useEffect(() => {
if (data) {
form.reset({
Expand Down Expand Up @@ -744,15 +765,29 @@ export const AddDomain = ({ id, type, domainId = "", children }: Props) => {
<FormLabel>Certificate Provider</FormLabel>
<Select
onValueChange={(value) => {
field.onChange(value);
if (value !== "custom") {
if (value.startsWith("resolver:")) {
field.onChange("custom");
form.setValue(
"customCertResolver",
undefined,
value.slice("resolver:".length),
);
} else {
field.onChange(value);
if (
value !== "custom" ||
(customCertResolver &&
certificateResolvers?.includes(
customCertResolver,
))
) {
form.setValue(
"customCertResolver",
undefined,
);
}
}
}}
value={field.value}
value={certSelectValue}
>
<FormControl>
<SelectTrigger>
Expand All @@ -765,6 +800,18 @@ export const AddDomain = ({ id, type, domainId = "", children }: Props) => {
Let's Encrypt
</SelectItem>
<SelectItem value={"custom"}>Custom</SelectItem>
{certificateResolvers
?.filter(
(resolver) => resolver !== "letsencrypt",
)
.map((resolver) => (
<SelectItem
key={resolver}
value={`resolver:${resolver}`}
>
{resolver}
</SelectItem>
))}
</SelectContent>
</Select>
<FormDescription>
Expand Down Expand Up @@ -804,7 +851,7 @@ export const AddDomain = ({ id, type, domainId = "", children }: Props) => {
}}
/>

{certificateType === "custom" && (
{certSelectValue === "custom" && (
<FormField
control={form.control}
name="customCertResolver"
Expand Down
21 changes: 21 additions & 0 deletions apps/dokploy/server/api/routers/domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import {
findPreviewDeploymentById,
findServerById,
generateTraefikMeDomain,
getCertificateResolvers,
getWebServerSettings,
IS_CLOUD,
manageDomain,
removeDomain,
removeDomainById,
Expand Down Expand Up @@ -100,6 +102,25 @@ export const domainRouter = createTRPCRouter({
return settings?.serverIp || "";
}),

certificateResolvers: withPermission("domain", "read")
.input(z.object({ serverId: z.string().optional() }))
.query(async ({ input, ctx }) => {
if (input.serverId) {
const server = await findServerById(input.serverId);
if (server.organizationId !== ctx.session.activeOrganizationId) {
throw new TRPCError({
code: "UNAUTHORIZED",
message: "You don't have access to this server",
});
}
return getCertificateResolvers(input.serverId);
}
if (IS_CLOUD) {
return [];
}
return getCertificateResolvers();
}),

update: protectedProcedure
.input(apiUpdateDomain)
.mutation(async ({ input, ctx }) => {
Expand Down
28 changes: 28 additions & 0 deletions packages/server/src/utils/traefik/web-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { join } from "node:path";
import { paths } from "@dokploy/server/constants";
import type { webServerSettings } from "@dokploy/server/db/schema/web-server-settings";
import { parse, stringify } from "yaml";
import { execAsyncRemote } from "../process/execAsync";
import {
loadOrCreateConfig,
removeTraefikConfig,
Expand Down Expand Up @@ -109,6 +110,33 @@ export const readMainConfig = () => {
return null;
};

export const getCertificateResolvers = async (
serverId?: string | null,
): Promise<string[]> => {
try {
let yamlStr: string | null = null;
if (serverId) {
const { MAIN_TRAEFIK_PATH } = paths(true);
const configPath = join(MAIN_TRAEFIK_PATH, "traefik.yml");
const { stdout } = await execAsyncRemote(serverId, `cat ${configPath}`);
yamlStr = stdout || null;
} else {
yamlStr = readMainConfig();
}
if (!yamlStr) return [];
const config = parse(yamlStr) as MainTraefikConfig;
if (
!config?.certificatesResolvers ||
typeof config.certificatesResolvers !== "object"
) {
return [];
}
return Object.keys(config.certificatesResolvers);
} catch {
return [];
}
Comment on lines +135 to +137

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Resolver discovery errors are hidden

The catch-all converts SSH, file-access, and YAML-parsing errors into an empty resolver list, making configured providers disappear from the selector without giving users or operators any diagnostic that discovery failed.

};

export const writeMainConfig = (traefikConfig: string) => {
try {
const { MAIN_TRAEFIK_PATH } = paths();
Expand Down