feat: add middlewares to domains

This commit is contained in:
David Eiber
2026-01-01 15:26:21 +01:00
parent 9498fbeff3
commit ce5ad35981
11 changed files with 7267 additions and 2 deletions

View File

@@ -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());

View File

@@ -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) {

View File

@@ -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(

View File

@@ -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") {