A one-of-a-kind resume builder that keeps your privacy in mind. Completely secure, customizable, portable, open-source and free forever. Try it out today!
TypeScript agent-skillsaidsh-pluginhacktoberfestjavascriptmcp-serverreactresume-builderself-hostedtypescript
fix(custom-domain): return an empty Traefik configuration when no domain is verified
Amruth Pillaid456abfca1ff
diff --git a/apps/server/src/http/custom-domain.test.ts b/apps/server/src/http/custom-domain.test.tsindex 3970876b1..60872eaa9 100644--- a/apps/server/src/http/custom-domain.test.ts+++ b/apps/server/src/http/custom-domain.test.ts@@ -1,7 +1,7 @@import { describe, expect, it, vi } from "vite-plus/test";const secret = "s".repeat(40);-const mocks = vi.hoisted(() => ({ traefikConfiguration: vi.fn(async () => ({ http: { routers: {} } })) }));+const mocks = vi.hoisted(() => ({ traefikConfiguration: vi.fn(async () => ({})) }));vi.mock("@reactive-resume/env/server", () => ({env: { APP_URL: "https://rxresu.me", CUSTOM_DOMAIN_PROVIDER_SECRET: "s".repeat(40) },diff --git a/packages/api/src/features/custom-domain/service.test.ts b/packages/api/src/features/custom-domain/service.test.tsindex 6c8a2f942..dedcb92ed 100644--- a/packages/api/src/features/custom-domain/service.test.ts+++ b/packages/api/src/features/custom-domain/service.test.ts@@ -1,6 +1,14 @@import { describe, expect, it, vi } from "vite-plus/test";-vi.mock("@reactive-resume/db/client", () => ({ db: {} }));+const verified = vi.hoisted(() => [] as { userId: string; hostname: string }[]);+// Verified domains for the provider; the background re-check finds none stale.+vi.mock("@reactive-resume/db/client", () => ({+ db: {+ select: () => ({+ from: () => ({ where: () => Object.assign(Promise.resolve(verified), { limit: async () => [] }) }),+ }),+ },+}));vi.mock("@reactive-resume/env/server", () => ({env: {APP_URL: "https://rxresu.me",@@ -10,7 +18,7 @@ vi.mock("@reactive-resume/env/server", () => ({},}));-const { normalizeHostname } = await import("./service");+const { normalizeHostname, traefikConfiguration } = await import("./service");describe("normalizeHostname", () => {it.each([@@ -39,3 +47,28 @@ describe("normalizeHostname", () => {expect(normalizeHostname(input)).toBeNull();});});++describe("traefikConfiguration", () => {+ const options = { service: "app@swarm", entryPoint: "websecure", certResolver: "customdomains" };++ it("sends Traefik an empty document, not an empty map, when no domain is verified", async () => {+ verified.length = 0;+ expect(await traefikConfiguration(options)).toEqual({});+ });++ it("routes each verified domain to the app with its own certificate", async () => {+ verified.splice(0, verified.length, { userId: "u1", hostname: "resume.example.com" });+ expect(await traefikConfiguration(options)).toEqual({+ http: {+ routers: {+ "custom-domain-u1": {+ rule: "Host(`resume.example.com`)",+ entryPoints: ["websecure"],+ service: "app@swarm",+ tls: { certResolver: "customdomains" },+ },+ },+ },+ });+ });+});diff --git a/packages/api/src/features/custom-domain/service.ts b/packages/api/src/features/custom-domain/service.tsindex 52b1bca75..179f4b9b9 100644--- a/packages/api/src/features/custom-domain/service.ts+++ b/packages/api/src/features/custom-domain/service.ts@@ -210,7 +210,8 @@ export async function traefikConfiguration(options: { service: string; entryPoin},]),);- return { http: { routers } };+ // Traefik rejects an empty map ("routers cannot be a standalone element"), but accepts an empty document.+ return domains.length > 0 ? { http: { routers } } : {};}let rechecking = false;