diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index 3e6a921..99c9a99 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -36,6 +36,11 @@ services: - coolify - default restart: unless-stopped + labels: + - traefik.enable=true + - traefik.http.routers.rebours.rule=Host(`rebours.studio`) + - traefik.http.routers.rebours.entrypoints=http + - traefik.http.services.rebours.loadbalancer.server.port=80 volumes: dist-data: diff --git a/docker/nginx.conf b/docker/nginx.conf index 8f51916..5420aa2 100644 --- a/docker/nginx.conf +++ b/docker/nginx.conf @@ -14,6 +14,23 @@ server { proxy_set_header X-Forwarded-Proto $scheme; } + # ── SEO proxy → Fastify (dynamique depuis DB) ───────────────────────────── + location = /robots.txt { + 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; + } + + location = /sitemap.xml { + 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; + } + # ── Admin proxy → Fastify (AdminJS) ────────────────────────────────────── location /admin { proxy_pass http://server:3001; diff --git a/server.mjs b/server.mjs index c9b6366..c326695 100644 --- a/server.mjs +++ b/server.mjs @@ -1,17 +1,12 @@ import Fastify from 'fastify' import cors from '@fastify/cors' -import fastifyStatic from '@fastify/static' import Stripe from 'stripe' import dotenv from 'dotenv' -import { fileURLToPath } from 'url' -import { dirname, join } from 'path' import { setupAdmin } from './admin.mjs' import { prisma } from './src/lib/db.mjs' dotenv.config() -const __dirname = dirname(fileURLToPath(import.meta.url)) - const stripe = new Stripe(process.env.STRIPE_SECRET_KEY ?? '') const DOMAIN = process.env.DOMAIN ?? 'http://localhost:4321' @@ -153,30 +148,6 @@ app.get('/api/session/:id', async (request) => { } }) -// ── Static files (prod only — en dev, Vite/Astro s'en charge) ─────────── -if (process.env.NODE_ENV === 'production') { - await app.register(fastifyStatic, { - root: join(__dirname, 'dist'), - prefix: '/', - decorateReply: false, - setHeaders(res, path) { - if (path.endsWith('.html')) { - res.setHeader('Cache-Control', 'no-store') - } else { - res.setHeader('Cache-Control', 'public, max-age=31536000, immutable') - } - }, - }) - - // SPA fallback — sert index.html pour les routes Astro - app.setNotFoundHandler(async (request, reply) => { - if (request.url.startsWith('/api') || request.url.startsWith('/admin')) { - return reply.code(404).send({ error: 'Not found' }) - } - return reply.sendFile('index.html') - }) -} - // ── Start ─────────────────────────────────────────────────────────────────── try { await app.listen({ port: process.env.PORT ?? 3000, host: '0.0.0.0' })