File size: 1,862 Bytes
d543fc1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

// https://vite.dev/config/
export default defineConfig({
  plugins: [react()],
  server: {
    watch: {
      usePolling: true,
    },
    hmr: true,
    proxy: {
      '/api': {
        target: 'http://127.0.0.1:5000',
        changeOrigin: true,
        secure: false,
        ws: true,
        timeout: 30000,          // 30s proxy timeout
        proxyTimeout: 30000,     // 30s backend response timeout
        configure: (proxy) => {
          // Use setTimeout to run after Vite attaches its own error handler
          setTimeout(() => {
            // Remove existing error listeners (Vite's default noisy logger)
            proxy.removeAllListeners('error');
            
            // Attach our own silent error handler
            proxy.on('error', (err, req, res) => {
              // Only log non-ECONNREFUSED errors
              if (err.code !== 'ECONNREFUSED') {
                console.warn(`[WSS Proxy] ${req.method} ${req.url}${err.message}`);
              }
              
              // Return a clean JSON error to the frontend instead of crashing
              if (res && !res.headersSent) {
                res.writeHead(503, { 'Content-Type': 'application/json' });
                res.end(JSON.stringify({
                  error: 'backend_unavailable',
                  message: 'Flask backend is not ready yet.'
                }));
              }
            });
          }, 0);

          proxy.on('proxyReq', (proxyReq, req) => {
            // Suppress the spammy proxy logs in the console
            // by leaving this empty or only logging specific things if needed.
          });
        }
      },
      '/uploads': {
        target: 'http://127.0.0.1:5000',
        changeOrigin: true,
        secure: false
      }
    }
  }
})