FROM node:20-alpine

WORKDIR /app

COPY ndf/package.json ndf/package-lock.json ./
RUN npm ci --legacy-peer-deps

COPY ndf/ .

# ✅ Écrase vite.config.ts avec la bonne config
RUN cat > /app/vite.config.ts << 'EOF'
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import path from 'path';

export default defineConfig({
  plugins: [react()],
  resolve: {
    alias: { '@': path.resolve(__dirname, './src') }
  },
  server: {
    host: '0.0.0.0',
    port: 81,
    strictPort: true,
    allowedHosts: ['myndf.ensup-adm.net', 'localhost'],
    proxy: {
      '/api': {
        target: 'http://backend:3024',
        changeOrigin: true,
        secure: false,
        ws: true
      }
    }
  }
});
EOF

EXPOSE 81

CMD ["npx", "vite", "--host", "0.0.0.0", "--port", "81"]
