vite.config.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { defineConfig } from 'vite'
  2. import react from '@vitejs/plugin-react'
  3. import path from 'path'
  4. // https://vite.dev/config/
  5. export default defineConfig({
  6. plugins: [react()],
  7. resolve: {
  8. alias: {
  9. '@': path.resolve(__dirname, './src'),
  10. },
  11. },
  12. server: {
  13. port: 5173,
  14. proxy: {
  15. // WebSocket endpoints
  16. '/ws': {
  17. target: 'ws://localhost:8080',
  18. ws: true,
  19. // Suppress connection reset errors (common during backend restarts)
  20. configure: (proxy, _options) => {
  21. // Handle proxy errors silently for expected connection issues
  22. const handleError = (err: Error) => {
  23. const msg = err.message || ''
  24. if (msg.includes('ECONNRESET') || msg.includes('ECONNREFUSED') || msg.includes('EPIPE')) {
  25. return // Silently ignore
  26. }
  27. console.error('WebSocket proxy error:', msg)
  28. }
  29. proxy.on('error', handleError)
  30. proxy.on('proxyReqWs', (_proxyReq, _req, socket) => {
  31. socket.on('error', handleError)
  32. })
  33. },
  34. },
  35. // API endpoints - proxy all backend routes
  36. '/send_home': 'http://localhost:8080',
  37. '/send_coordinate': 'http://localhost:8080',
  38. '/stop_execution': 'http://localhost:8080',
  39. '/move_to_center': 'http://localhost:8080',
  40. '/move_to_perimeter': 'http://localhost:8080',
  41. '/set_speed': 'http://localhost:8080',
  42. '/run_theta_rho': 'http://localhost:8080',
  43. '/pause_execution': 'http://localhost:8080',
  44. '/resume_execution': 'http://localhost:8080',
  45. '/serial_status': 'http://localhost:8080',
  46. '/connect': 'http://localhost:8080',
  47. '/disconnect': 'http://localhost:8080',
  48. '/get_speed': 'http://localhost:8080',
  49. '/list_theta_rho_files': 'http://localhost:8080',
  50. '/list_theta_rho_files_with_metadata': 'http://localhost:8080',
  51. '/list_all_playlists': 'http://localhost:8080',
  52. '/get_playlist': 'http://localhost:8080',
  53. '/create_playlist': 'http://localhost:8080',
  54. '/modify_playlist': 'http://localhost:8080',
  55. '/delete_playlist': 'http://localhost:8080',
  56. '/rename_playlist': 'http://localhost:8080',
  57. '/run_playlist': 'http://localhost:8080',
  58. '/add_to_playlist': 'http://localhost:8080',
  59. '/preview_thr': 'http://localhost:8080',
  60. '/preview_thr_batch': 'http://localhost:8080',
  61. '/preview': 'http://localhost:8080',
  62. '/get_theta_rho_coordinates': 'http://localhost:8080',
  63. '/get_led_config': 'http://localhost:8080',
  64. '/set_led_config': 'http://localhost:8080',
  65. '/api': 'http://localhost:8080',
  66. '/restart': 'http://localhost:8080',
  67. '/static': 'http://localhost:8080',
  68. },
  69. },
  70. build: {
  71. outDir: '../static/dist',
  72. emptyOutDir: true,
  73. },
  74. })