correcgt
This commit is contained in:
parent
05b49baae9
commit
e8b71e7603
@ -3,8 +3,6 @@ services:
|
|||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
volumes:
|
|
||||||
- static:/app/dist
|
|
||||||
environment:
|
environment:
|
||||||
- DATABASE_URL
|
- DATABASE_URL
|
||||||
- STRIPE_SECRET_KEY
|
- STRIPE_SECRET_KEY
|
||||||
@ -18,27 +16,8 @@ services:
|
|||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
labels:
|
labels:
|
||||||
- traefik.enable=true
|
- traefik.enable=true
|
||||||
- traefik.http.routers.api.rule=Host(`rebours.studio`) && (PathPrefix(`/api`) || PathPrefix(`/admin`))
|
- traefik.http.routers.rebours.rule=Host(`rebours.studio`)
|
||||||
- traefik.http.routers.api.entrypoints=https
|
- traefik.http.routers.rebours.entrypoints=https
|
||||||
- traefik.http.routers.api.tls=true
|
- traefik.http.routers.rebours.tls=true
|
||||||
- traefik.http.routers.api.tls.certresolver=letsencrypt
|
- traefik.http.routers.rebours.tls.certresolver=letsencrypt
|
||||||
- traefik.http.services.api.loadbalancer.server.port=3000
|
- traefik.http.services.rebours.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:
|
|
||||||
|
|||||||
29
server.mjs
29
server.mjs
@ -1,12 +1,17 @@
|
|||||||
import Fastify from 'fastify'
|
import Fastify from 'fastify'
|
||||||
import cors from '@fastify/cors'
|
import cors from '@fastify/cors'
|
||||||
|
import fastifyStatic from '@fastify/static'
|
||||||
import Stripe from 'stripe'
|
import Stripe from 'stripe'
|
||||||
import dotenv from 'dotenv'
|
import dotenv from 'dotenv'
|
||||||
|
import { fileURLToPath } from 'url'
|
||||||
|
import { dirname, join } from 'path'
|
||||||
import { setupAdmin } from './admin.mjs'
|
import { setupAdmin } from './admin.mjs'
|
||||||
import { prisma } from './src/lib/db.mjs'
|
import { prisma } from './src/lib/db.mjs'
|
||||||
|
|
||||||
dotenv.config()
|
dotenv.config()
|
||||||
|
|
||||||
|
const __dirname = dirname(fileURLToPath(import.meta.url))
|
||||||
|
|
||||||
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY ?? '')
|
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY ?? '')
|
||||||
const DOMAIN = process.env.DOMAIN ?? 'http://localhost:4321'
|
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 ───────────────────────────────────────────────────────────────────
|
// ── Start ───────────────────────────────────────────────────────────────────
|
||||||
try {
|
try {
|
||||||
await app.listen({ port: process.env.PORT ?? 3000, host: '0.0.0.0' })
|
await app.listen({ port: process.env.PORT ?? 3000, host: '0.0.0.0' })
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user