This commit is contained in:
ordinarthur 2026-03-12 16:14:28 +01:00
parent 05b49baae9
commit e8b71e7603
2 changed files with 34 additions and 26 deletions

View File

@ -3,8 +3,6 @@ services:
build:
context: .
dockerfile: Dockerfile
volumes:
- static:/app/dist
environment:
- DATABASE_URL
- STRIPE_SECRET_KEY
@ -18,27 +16,8 @@ services:
restart: unless-stopped
labels:
- traefik.enable=true
- traefik.http.routers.api.rule=Host(`rebours.studio`) && (PathPrefix(`/api`) || PathPrefix(`/admin`))
- traefik.http.routers.api.entrypoints=https
- traefik.http.routers.api.tls=true
- traefik.http.routers.api.tls.certresolver=letsencrypt
- traefik.http.services.api.loadbalancer.server.port=3000
- traefik.http.routers.api.priority=2
nginx:
image: nginx:alpine
volumes:
- static:/usr/share/nginx/html:ro
- ./docker/nginx.conf:/etc/nginx/conf.d/default.conf:ro
restart: unless-stopped
labels:
- traefik.enable=true
- traefik.http.routers.static.rule=Host(`rebours.studio`)
- traefik.http.routers.static.entrypoints=https
- traefik.http.routers.static.tls=true
- traefik.http.routers.static.tls.certresolver=letsencrypt
- traefik.http.services.static.loadbalancer.server.port=80
- traefik.http.routers.static.priority=1
volumes:
static:
- traefik.http.routers.rebours.rule=Host(`rebours.studio`)
- traefik.http.routers.rebours.entrypoints=https
- traefik.http.routers.rebours.tls=true
- traefik.http.routers.rebours.tls.certresolver=letsencrypt
- traefik.http.services.rebours.loadbalancer.server.port=3000

View File

@ -1,12 +1,17 @@
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'
@ -148,6 +153,30 @@ 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' })