mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-06-27 10:05:32 +02:00
feat: add middlewares to domains
This commit is contained in:
@@ -53,6 +53,7 @@ export const domains = pgTable("domain", {
|
||||
certificateType: certificateType("certificateType").notNull().default("none"),
|
||||
internalPath: text("internalPath").default("/"),
|
||||
stripPath: boolean("stripPath").notNull().default(false),
|
||||
middlewares: text("middlewares").array(),
|
||||
});
|
||||
|
||||
export const domainsRelations = relations(domains, ({ one }) => ({
|
||||
@@ -86,6 +87,7 @@ export const apiCreateDomain = createSchema.pick({
|
||||
previewDeploymentId: true,
|
||||
internalPath: true,
|
||||
stripPath: true,
|
||||
middlewares: true,
|
||||
});
|
||||
|
||||
export const apiFindDomain = createSchema
|
||||
@@ -118,5 +120,6 @@ export const apiUpdateDomain = createSchema
|
||||
domainType: true,
|
||||
internalPath: true,
|
||||
stripPath: true,
|
||||
middlewares: true,
|
||||
})
|
||||
.merge(createSchema.pick({ domainId: true }).required());
|
||||
|
||||
@@ -20,6 +20,7 @@ export const domain = z
|
||||
https: z.boolean().optional(),
|
||||
certificateType: z.enum(["letsencrypt", "none", "custom"]).optional(),
|
||||
customCertResolver: z.string(),
|
||||
middlewares: z.array(z.string()).optional(),
|
||||
})
|
||||
.superRefine((input, ctx) => {
|
||||
if (input.https && !input.certificateType) {
|
||||
@@ -83,6 +84,7 @@ export const domainCompose = z
|
||||
certificateType: z.enum(["letsencrypt", "none", "custom"]).optional(),
|
||||
customCertResolver: z.string(),
|
||||
serviceName: z.string().min(1, { message: "Service name is required" }),
|
||||
middlewares: z.array(z.string()).optional(),
|
||||
})
|
||||
.superRefine((input, ctx) => {
|
||||
if (input.https && !input.certificateType) {
|
||||
|
||||
@@ -302,6 +302,11 @@ export const createDomainLabels = (
|
||||
middlewares.push(middlewareName);
|
||||
}
|
||||
|
||||
// Add custom middlewares
|
||||
if (domain.middlewares?.length) {
|
||||
middlewares.push(...domain.middlewares);
|
||||
}
|
||||
|
||||
// Apply middlewares to router if any exist
|
||||
if (middlewares.length > 0) {
|
||||
labels.push(
|
||||
|
||||
@@ -133,7 +133,7 @@ export const createRouterConfig = async (
|
||||
}
|
||||
|
||||
if (entryPoint === "web" && https) {
|
||||
routerConfig.middlewares = ["redirect-to-https"];
|
||||
routerConfig.middlewares?.unshift("redirect-to-https");
|
||||
}
|
||||
|
||||
if ((entryPoint === "websecure" && https) || !https) {
|
||||
@@ -160,6 +160,11 @@ export const createRouterConfig = async (
|
||||
}
|
||||
routerConfig.middlewares?.push(middlewareName);
|
||||
}
|
||||
|
||||
// custom middlewares from domain
|
||||
if (domain.middlewares && domain.middlewares.length > 0) {
|
||||
routerConfig.middlewares?.push(...domain.middlewares);
|
||||
}
|
||||
}
|
||||
|
||||
if (entryPoint === "websecure") {
|
||||
|
||||
Reference in New Issue
Block a user