From eeb902521096968019207fa54408aa9c1e7dd796 Mon Sep 17 00:00:00 2001 From: ordinarthur <@arthurbarre.js@gmail.com> Date: Thu, 12 Mar 2026 20:03:57 +0100 Subject: [PATCH] correct config --- Dockerfile | 4 ++-- docker-compose.prod.yml | 25 ++++++++++++++++++++++--- docker/nginx.conf | 33 ++++++++++++++++++++++++++------- 3 files changed, 50 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index 08d2917..a4d074b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,7 +16,7 @@ COPY --from=deps /app/node_modules ./node_modules COPY . . RUN pnpm prisma generate -EXPOSE 80 +EXPOSE 3001 -# Astro SSG needs the DB at build time → build happens at startup after Postgres is ready +# Build Astro (needs DB) then start Fastify API CMD ["sh", "-c", "pnpm prisma migrate deploy && pnpm build && node server.mjs"] diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index 069dc26..ccf6b30 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -1,25 +1,44 @@ services: - fastify: + server: build: context: . dockerfile: Dockerfile expose: - - '80' + - '3001' environment: - DATABASE_URL - STRIPE_SECRET_KEY - STRIPE_WEBHOOK_SECRET - DOMAIN - - PORT=80 + - PORT=3001 - ADMIN_EMAIL - ADMIN_PASSWORD - COOKIE_SECRET - NODE_ENV=production + volumes: + - dist-data:/app/dist networks: - coolify - default restart: unless-stopped + client: + image: nginx:alpine + expose: + - '80' + volumes: + - dist-data:/usr/share/nginx/html:ro + - ./docker/nginx.conf:/etc/nginx/conf.d/default.conf:ro + depends_on: + - server + networks: + - coolify + - default + restart: unless-stopped + +volumes: + dist-data: + networks: coolify: external: true diff --git a/docker/nginx.conf b/docker/nginx.conf index e5265c6..8f51916 100644 --- a/docker/nginx.conf +++ b/docker/nginx.conf @@ -5,26 +5,45 @@ server { root /usr/share/nginx/html; index index.html; - # HTML : jamais caché - location ~* \.html$ { - add_header Cache-Control "no-store"; + # ── API proxy → Fastify ────────────────────────────────────────────────── + location /api/ { + proxy_pass http://server:3001; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; } - # Fichiers Astro avec hash dans _astro/ : cache long immutable - location ~* ^/_astro/ { + # ── Admin proxy → Fastify (AdminJS) ────────────────────────────────────── + location /admin { + proxy_pass http://server:3001; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + + # ── Cache : Astro hashed files → immutable ─────────────────────────────── + location /_astro/ { add_header Cache-Control "public, max-age=31536000, immutable"; } - # CSS / JS sans hash (style.css, main.js) : revalidation + # ── Cache : CSS/JS sans hash → revalidation ───────────────────────────── location ~* \.(css|js)$ { add_header Cache-Control "no-cache"; } - # Assets (images, fonts) : cache 7 jours + # ── Cache : assets (images, fonts) → 7 jours ──────────────────────────── location ~* \.(jpg|jpeg|png|gif|webp|svg|woff2|woff|ttf|ico)$ { add_header Cache-Control "public, max-age=604800"; } + # ── HTML : jamais caché ────────────────────────────────────────────────── + location ~* \.html$ { + add_header Cache-Control "no-store"; + } + + # ── SPA fallback pour les routes Astro ─────────────────────────────────── location / { try_files $uri $uri/ $uri.html /index.html; }