From aedf149471235ac6a6a157c6f66cda32c2f2045b Mon Sep 17 00:00:00 2001 From: Lukas May Date: Thu, 5 Mar 2026 22:16:19 +0100 Subject: [PATCH] fix: Use container-internal port 80 in gateway Caddyfile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Caddyfile was using the host port (e.g., 9100) as the Caddy listen address, but Docker maps host:9100 → container:80. Caddy inside the container was listening on 9100 while Docker only forwarded to port 80, causing all health checks to fail with "connection reset by peer". --- apps/server/preview/compose-generator.test.ts | 4 ++-- apps/server/preview/gateway.ts | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/apps/server/preview/compose-generator.test.ts b/apps/server/preview/compose-generator.test.ts index 37aebf2..1e1f650 100644 --- a/apps/server/preview/compose-generator.test.ts +++ b/apps/server/preview/compose-generator.test.ts @@ -164,7 +164,7 @@ describe('generateGatewayCaddyfile', () => { const caddyfile = generateGatewayCaddyfile(previews, 9100); expect(caddyfile).toContain('auto_https off'); - expect(caddyfile).toContain('localhost:9100 {'); + expect(caddyfile).toContain(':80 {'); expect(caddyfile).toContain('handle_path /abc123/*'); expect(caddyfile).toContain('reverse_proxy cw-preview-abc123-app:3000'); }); @@ -193,7 +193,7 @@ describe('generateGatewayCaddyfile', () => { ]); const caddyfile = generateGatewayCaddyfile(previews, 9100); - expect(caddyfile).toContain('localhost:9100 {'); + expect(caddyfile).toContain(':80 {'); expect(caddyfile).toContain('handle_path /abc/*'); expect(caddyfile).toContain('handle_path /xyz/*'); expect(caddyfile).toContain('reverse_proxy cw-preview-abc-app:3000'); diff --git a/apps/server/preview/gateway.ts b/apps/server/preview/gateway.ts index c9b67c0..57536c5 100644 --- a/apps/server/preview/gateway.ts +++ b/apps/server/preview/gateway.ts @@ -201,14 +201,16 @@ export class GatewayManager { */ export function generateGatewayCaddyfile( previews: Map, - port: number, + _port: number, ): string { + // Caddy runs inside a container where Docker maps host:${port} → container:80. + // The Caddyfile must listen on the container-internal port (80), not the host port. const lines: string[] = [ '{', ' auto_https off', '}', '', - `localhost:${port} {`, + `:80 {`, ]; for (const [previewId, routes] of previews) {