diff --git a/docs/DEPLOYMENT_FIXES_2025-09-24.md b/docs/DEPLOYMENT_FIXES_2025-09-24.md new file mode 100644 index 00000000..19219c6c --- /dev/null +++ b/docs/DEPLOYMENT_FIXES_2025-09-24.md @@ -0,0 +1,78 @@ +# Corrections de déploiement - 24 septembre 2025 + +## Problèmes résolus + +### 1. Configuration Next.js conditionnelle +- **Problème**: `output: 'export'` et `basePath` appliqués en dev bloquaient HMR +- **Solution**: Configuration conditionnelle dans `next.config.js` + ```js + const isProd = process.env.NODE_ENV === 'production'; + const nextConfig = { + ...(isProd ? { + output: 'export', + basePath: '/lecoffre', + assetPrefix: '/lecoffre', + trailingSlash: true, + images: { unoptimized: true } + } : {}) + }; + ``` + +### 2. Nginx - Redirection et proxy +- **Problème**: `/lecoffre/` retournait 404 car l'image CI ne respectait pas `basePath` +- **Solution**: Rewrite Nginx dans `location ^~ /lecoffre/` + ```nginx + rewrite ^/lecoffre/(.*)$ /$1 break; + proxy_pass http://localhost:3004; + ``` + +### 3. Assets Next.js manquants +- **Problème**: `/_next/static/` retournait 404 (assets non servis) +- **Solution**: Route Nginx dédiée + ```nginx + location ^~ /_next/ { + proxy_pass http://localhost:3004/_next/; + add_header Cache-Control "public, max-age=31536000, immutable"; + } + ``` + +### 4. HMR en développement +- **Problème**: Besoin d'HMR sans impacter la prod +- **Solution**: Route dédiée `/lecoffre-hmr/` avec WebSocket support + ```nginx + location ^~ /lecoffre-hmr/ { + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + rewrite ^/lecoffre-hmr/(.*)$ /$1 break; + proxy_pass http://localhost:3000; + } + ``` + +## Architecture finale + +### Production +- `https://dev4.4nkweb.com/` → ihm_client (iframe) +- `https://dev4.4nkweb.com/lecoffre/` → lecoffre-front (app principale) +- `https://dev4.4nkweb.com/_next/` → assets Next.js + +### Développement (HMR) +- `https://dev4.4nkweb.com/lecoffre-hmr/` → Next.js dev server (port 3000) + +### Flux IdNot +- CORS dev3 configuré pour `https://dev4.4nkweb.com` +- State management via `/api/v1/idnot/state` sur dev3 +- Callback vers `/authorized-client` (prod ou HMR) + +## Variables d'environnement +- `NEXT_PUBLIC_*` cohérentes entre build CI et runtime +- `NODE_ENV=production` pour activer basePath/export +- CORS dynamique pour dev4.4nkweb.com + +## Tests validés +- ✅ Redirection 301: `/lecoffre` → `/lecoffre/` +- ✅ Page d'accueil: `/lecoffre/` → 200 +- ✅ Assets: `/_next/static/` → 200 +- ✅ HMR: `/lecoffre-hmr/` → 200 +- ✅ CORS dev3: OPTIONS 204 + POST state 200 +- ✅ ihm_client: `/` → 200 diff --git a/next.config.js b/next.config.js index 605c8b9c..dea91826 100644 --- a/next.config.js +++ b/next.config.js @@ -1,14 +1,18 @@ /** @type {import('next').NextConfig} */ +const isProd = process.env.NODE_ENV === 'production'; + const nextConfig = { reactStrictMode: false, - output: 'export', - basePath: '/lecoffre', - assetPrefix: '/lecoffre', - trailingSlash: true, - images: { - unoptimized: true, - }, + ...(isProd + ? { + output: 'export', + basePath: '/lecoffre', + assetPrefix: '/lecoffre', + trailingSlash: true, + images: { unoptimized: true }, + } + : {}), eslint: { ignoreDuringBuilds: true, },