vite.config.ts 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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: parseInt(process.env.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. '/skip_pattern': 'http://localhost:8080',
  46. '/serial_status': 'http://localhost:8080',
  47. '/list_serial_ports': 'http://localhost:8080',
  48. '/connect': 'http://localhost:8080',
  49. '/disconnect': 'http://localhost:8080',
  50. '/get_speed': 'http://localhost:8080',
  51. '/list_theta_rho_files': 'http://localhost:8080',
  52. '/list_theta_rho_files_with_metadata': 'http://localhost:8080',
  53. '/list_all_playlists': 'http://localhost:8080',
  54. '/get_playlist': 'http://localhost:8080',
  55. '/create_playlist': 'http://localhost:8080',
  56. '/modify_playlist': 'http://localhost:8080',
  57. '/delete_playlist': 'http://localhost:8080',
  58. '/rename_playlist': 'http://localhost:8080',
  59. '/run_playlist': 'http://localhost:8080',
  60. '/add_to_playlist': 'http://localhost:8080',
  61. '/preview_thr': 'http://localhost:8080',
  62. '/preview_thr_batch': 'http://localhost:8080',
  63. '/preview': 'http://localhost:8080',
  64. '/get_theta_rho_coordinates': 'http://localhost:8080',
  65. '/get_led_config': 'http://localhost:8080',
  66. '/set_led_config': 'http://localhost:8080',
  67. '/api': 'http://localhost:8080',
  68. '/restart': 'http://localhost:8080',
  69. '/static': 'http://localhost:8080',
  70. },
  71. },
  72. build: {
  73. outDir: '../static/dist',
  74. emptyOutDir: true,
  75. },
  76. })