import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' // https://vite.dev/config/ export default defineConfig({ plugins: [react()], server: { port: 3000, proxy: { // Proxy API requests to Frappe backend '/api': { target: process.env.VITE_FRAPPE_BASE_URL || 'https://seeraasm-med.seeraarabia.com', changeOrigin: true, secure: true, headers: { 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS', 'Access-Control-Allow-Headers': 'Content-Type, Authorization, X-Frappe-CSRF-Token', }, configure: (proxy, _options) => { proxy.on('error', (err, _req, _res) => { console.log('proxy error', err); }); proxy.on('proxyReq', (_proxyReq, req, _res) => { console.log('Sending Request to the Target:', req.method, req.url); }); proxy.on('proxyRes', (proxyRes, req, _res) => { console.log('Received Response from the Target:', proxyRes.statusCode, req.url); // Add CORS headers to the response proxyRes.headers['Access-Control-Allow-Origin'] = '*'; proxyRes.headers['Access-Control-Allow-Methods'] = 'GET, POST, PUT, DELETE, OPTIONS'; proxyRes.headers['Access-Control-Allow-Headers'] = 'Content-Type, Authorization, X-Frappe-CSRF-Token'; }); }, }, // Proxy file requests to Frappe backend '/files': { target: process.env.VITE_FRAPPE_BASE_URL || 'https://seeraasm-med.seeraarabia.com', changeOrigin: true, secure: true, // Keep the /files path as-is when forwarding to the target configure: (proxy, _options) => { proxy.on('proxyReq', (proxyReq, req, _res) => { // Log for debugging if (process.env.DEV) { console.log('Proxying file request:', req.url, 'to', proxyReq.path); } }); }, } } }, build: { outDir: 'dist', assetsDir: 'assets', sourcemap: false, rollupOptions: { output: { manualChunks: { vendor: ['react', 'react-dom'], router: ['react-router-dom'] } } } } })