From 51bcd9881e5c8fc3e9fb8068f9a6ee24f2416b2b Mon Sep 17 00:00:00 2001 From: JannikStreek Date: Sat, 30 May 2026 11:28:40 +0200 Subject: [PATCH] fix prod setup in readme with reverse proxy --- README.md | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9cf4e1f..c66fcf1 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,12 @@ Important: Currently, the backend is expected to run on the subdomain `write-bac ``` services: + caddy: + image: caddy:2 + ports: + - "80:80" + volumes: + - ./Caddyfile:/etc/caddy/Caddyfile editor: image: ghcr.io/b310-digital/groupwriter/groupwriter-frontend:latest ports: @@ -72,6 +78,34 @@ volumes: postgres_data: ``` +Create a `Caddyfile` next to the compose file: + +```caddyfile +http://write.localhost { + reverse_proxy editor:8080 +} + +http://write-backend.localhost { + # The backend sends no CORS headers, and the editor (write.localhost) is a + # different origin, so the proxy has to add them (including answering the + # preflight OPTIONS request the browser sends before POST/DELETE). + header { + Access-Control-Allow-Origin "http://write.localhost" + Access-Control-Allow-Methods "GET, POST, DELETE, OPTIONS" + Access-Control-Allow-Headers "Authorization, Content-Type" + } + + @options method OPTIONS + handle @options { + respond 204 + } + + handle { + reverse_proxy backend:3000 + } +} +``` + Example for a `.env` file: ``` @@ -93,7 +127,7 @@ Then start it: docker compose up -d ``` -And visit the app at `localhost:8080`! +And visit the app at `http://write.localhost`! ### Options and configurations