From a8ec0936d4fbb06c9aa81586815322e17889b51f Mon Sep 17 00:00:00 2001 From: Joyce <26967919+Joyce-O@users.noreply.github.com> Date: Wed, 21 Jan 2026 14:55:26 -0500 Subject: [PATCH] chore: improve production deployment flexibility - Switch frontend from nginx to caddy for consistency with Coolify - Make VITE_API_URL optional, auto-derive from window.location.origin/api - Simplifies deployment by not requiring build-time API URL Co-Authored-By: Claude Opus 4.5 --- docker-compose.prod.yml | 2 +- frontend/Dockerfile.prod | 22 ++++++++++------------ frontend/src/api/client.ts | 3 ++- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index 725fb6b..0bfe38b 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -41,7 +41,7 @@ services: context: ./frontend dockerfile: Dockerfile.prod args: - VITE_API_URL: ${VITE_API_URL:?VITE_API_URL required} + VITE_API_URL: ${VITE_API_URL:-} ports: - "8080:8080" depends_on: diff --git a/frontend/Dockerfile.prod b/frontend/Dockerfile.prod index a74cbe4..c9a4952 100644 --- a/frontend/Dockerfile.prod +++ b/frontend/Dockerfile.prod @@ -15,20 +15,18 @@ ENV VITE_API_URL=${VITE_API_URL} RUN npm run build # Production stage -FROM nginx:alpine +FROM caddy:alpine -COPY --from=builder /app/dist /usr/share/nginx/html +# Copy built assets +COPY --from=builder /app/dist /srv -# Handle client-side routing -RUN echo 'server { \ - listen 8080; \ - root /usr/share/nginx/html; \ - index index.html; \ - location / { \ - try_files $uri $uri/ /index.html; \ - } \ -}' > /etc/nginx/conf.d/default.conf +# Caddyfile for SPA routing +RUN echo ':8080 { \ + root * /srv \ + file_server \ + try_files {path} /index.html \ +}' > /etc/caddy/Caddyfile EXPOSE 8080 -CMD ["nginx", "-g", "daemon off;"] +CMD ["caddy", "run", "--config", "/etc/caddy/Caddyfile"] diff --git a/frontend/src/api/client.ts b/frontend/src/api/client.ts index 446cfac..450dfbb 100644 --- a/frontend/src/api/client.ts +++ b/frontend/src/api/client.ts @@ -1,4 +1,5 @@ -const API_URL = import.meta.env.VITE_API_URL || 'http://localhost:8000'; +// Use VITE_API_URL if set at build time, otherwise derive from current origin +const API_URL = import.meta.env.VITE_API_URL || `${window.location.origin}/api`; export interface ParticipantAPI { id: string;