Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

feat(selfhost): add single-domain Caddy setup (#899)

KimSeongJun100146c49ea0
diff --git a/.env.example b/.env.example
index b57ae5d916..7907b2b062 100644
--- a/.env.example
+++ b/.env.example
@@ -7,8 +7,10 @@ DATABASE_URL=postgres://multica:multica@localhost:5432/multica?sslmode=disable
# Server
PORT=8080
+APP_ENV=
+TASK_DOMAIN=localhost
JWT_SECRET=change-me-in-production
-MULTICA_SERVER_URL=ws://localhost:8080/ws
+MULTICA_SERVER_URL=http://localhost:8080
MULTICA_APP_URL=http://localhost:3000
MULTICA_DAEMON_CONFIG=
MULTICA_WORKSPACE_ID=
@@ -60,4 +62,4 @@ NEXT_PUBLIC_WS_URL=ws://localhost:8080/ws
# Remote API (optional) — set to proxy local frontend to a remote backend
# Leave empty to use local backend (localhost:8080)
-# REMOTE_API_URL=https://multica-api.copilothub.ai
+REMOTE_API_URL=http://localhost:8080
diff --git a/Caddyfile b/Caddyfile
new file mode 100644
index 0000000000..b9ec3d4652
--- /dev/null
+++ b/Caddyfile
@@ -0,0 +1,15 @@
+{$TASK_DOMAIN} {
+ @next_static path /_next/static/*
+ header @next_static Cache-Control "public, max-age=31536000, immutable, no-transform"
+
+ reverse_proxy /api/* backend:8080
+ reverse_proxy /auth/send-code backend:8080
+ reverse_proxy /auth/verify-code backend:8080
+ reverse_proxy /auth/google backend:8080
+ reverse_proxy /auth/logout backend:8080
+ reverse_proxy /ws backend:8080
+ reverse_proxy /ws/* backend:8080
+ reverse_proxy /health backend:8080
+ reverse_proxy /health/* backend:8080
+ reverse_proxy frontend:3000
+}
diff --git a/Dockerfile.web b/Dockerfile.web
index d1f507c5b5..96e24ee7e1 100644
--- a/Dockerfile.web
+++ b/Dockerfile.web
@@ -37,9 +37,11 @@ RUN pnpm install --frozen-lockfile --offline
# Set build-time env: tells Next.js rewrites to proxy API calls to the backend service
ARG REMOTE_API_URL=http://backend:8080
ARG NEXT_PUBLIC_GOOGLE_CLIENT_ID
+ARG NEXT_PUBLIC_API_URL
ARG NEXT_PUBLIC_WS_URL
ENV REMOTE_API_URL=$REMOTE_API_URL
ENV NEXT_PUBLIC_GOOGLE_CLIENT_ID=$NEXT_PUBLIC_GOOGLE_CLIENT_ID
+ENV NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL
ENV NEXT_PUBLIC_WS_URL=$NEXT_PUBLIC_WS_URL
ENV STANDALONE=true
diff --git a/apps/docs/content/docs/getting-started/self-hosting.mdx b/apps/docs/content/docs/getting-started/self-hosting.mdx
index 3db0342f97..98c0234659 100644
--- a/apps/docs/content/docs/getting-started/self-hosting.mdx
+++ b/apps/docs/content/docs/getting-started/self-hosting.mdx
@@ -315,6 +315,8 @@ api.example.com {
}
```
+For a single-domain setup, route the frontend and backend through one hostname and forward `/api`, `/auth`, `/ws`, and `/health` to the backend while sending everything else to the frontend. This repository now includes a root `Caddyfile` and `docker-compose.selfhost.yml` service for that pattern.
+
### Nginx
```nginx
diff --git a/docker-compose.selfhost.yml b/docker-compose.selfhost.yml
index 206557cff8..9f713d77fe 100644
--- a/docker-compose.selfhost.yml
+++ b/docker-compose.selfhost.yml
@@ -5,8 +5,8 @@
# # Edit .env — change JWT_SECRET at minimum
# docker compose -f docker-compose.selfhost.yml up -d
#
-# Frontend: http://localhost:3000
-# Backend: http://localhost:8080 (also used by CLI/daemon)
+# Frontend: https://$TASK_DOMAIN (via Caddy reverse proxy)
+# Backend: internal on backend:8080 (health exposed at /health through Caddy)
name: multica
@@ -35,12 +35,13 @@ services:
postgres:
condition: service_healthy
ports:
- - "${PORT:-8080}:8080"
+ - "127.0.0.1:${PORT:-8080}:8080"
environment:
DATABASE_URL: postgres://${POSTGRES_USER:-multica}:${POSTGRES_PASSWORD:-multica}@postgres:5432/${POSTGRES_DB:-multica}?sslmode=disable
+ APP_ENV: ${APP_ENV:-}
PORT: "8080"
JWT_SECRET: ${JWT_SECRET:-change-me-in-production}
- FRONTEND_ORIGIN: ${FRONTEND_ORIGIN:-http://localhost:3000}
+ FRONTEND_ORIGIN: ${FRONTEND_ORIGIN:-https://${TASK_DOMAIN:-localhost}}
CORS_ALLOWED_ORIGINS: ${CORS_ALLOWED_ORIGINS:-}
RESEND_API_KEY: ${RESEND_API_KEY:-}
RESEND_FROM_EMAIL: ${RESEND_FROM_EMAIL:[email protected]}
@@ -60,15 +61,35 @@ services:
context: .
dockerfile: Dockerfile.web
args:
- REMOTE_API_URL: http://backend:8080
+ REMOTE_API_URL: ${REMOTE_API_URL:-http://backend:8080}
NEXT_PUBLIC_GOOGLE_CLIENT_ID: ${NEXT_PUBLIC_GOOGLE_CLIENT_ID:-}
+ NEXT_PUBLIC_API_URL: ${NEXT_PUBLIC_API_URL:-}
NEXT_PUBLIC_WS_URL: ${NEXT_PUBLIC_WS_URL:-}
depends_on:
- backend
ports:
- - "${FRONTEND_PORT:-3000}:3000"
+ - "127.0.0.1:${FRONTEND_PORT:-3000}:3000"
environment:
HOSTNAME: "0.0.0.0"
+ NEXT_PUBLIC_API_URL: ${NEXT_PUBLIC_API_URL:-}
+ NEXT_PUBLIC_WS_URL: ${NEXT_PUBLIC_WS_URL:-}
+
+ caddy:
+ image: caddy:2-alpine
+ depends_on:
+ - frontend
+ - backend
+ ports:
+ - "80:80"
+ - "443:443"
+ environment:
+ TASK_DOMAIN: ${TASK_DOMAIN:-localhost}
+ volumes:
+ - ./Caddyfile:/etc/caddy/Caddyfile:ro
+ - caddy_data:/data
+ - caddy_config:/config
volumes:
pgdata:
+ caddy_data:
+ caddy_config: