vite.config.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { fileURLToPath, URL } from 'node:url'
  2. import { defineConfig } from 'vite'
  3. import vue from '@vitejs/plugin-vue'
  4. import vueJsx from '@vitejs/plugin-vue-jsx'
  5. // https://vite.dev/config/
  6. export default defineConfig({
  7. plugins: [
  8. vue(),
  9. vueJsx(),
  10. // vueDevTools(),
  11. ],
  12. css: {
  13. postcss: './postcss.config.js'
  14. },
  15. resolve: {
  16. alias: {
  17. '@': fileURLToPath(new URL('./src', import.meta.url))
  18. },
  19. },
  20. server: {
  21. fs: {
  22. // 允许访问上层目录的node_modules (用于KaTeX字体等资源)
  23. allow: ['..']
  24. },
  25. proxy: {
  26. // ===== TTS语音合成服务代理(最具体的路径,优先匹配) =====
  27. '/api/tts': {
  28. target: 'http://172.16.29.101:22000',
  29. changeOrigin: true,
  30. rewrite: (path) => path.replace(/^\/api\/tts/, '/tts'),
  31. configure: (proxy, options) => {
  32. proxy.on('error', (err, req, res) => {
  33. console.log('TTS代理错误:', err);
  34. });
  35. proxy.on('proxyReq', (proxyReq, req, res) => {
  36. console.log('TTS代理请求:', req.method, req.url);
  37. });
  38. proxy.on('proxyRes', (proxyRes, req, res) => {
  39. console.log('TTS代理响应:', proxyRes.statusCode, req.url);
  40. });
  41. }
  42. },
  43. // ===== ReportGenerator API 代理(最具体的路径,优先匹配) =====
  44. '/api/v1/report': {
  45. target: 'http://127.0.0.1:28002',
  46. changeOrigin: true
  47. },
  48. // ===== SSE控制API代理 =====
  49. '/api/v1/sse': {
  50. target: 'http://127.0.0.1:28002',
  51. changeOrigin: true
  52. },
  53. // ===== 新增:认证 API 代理(/api/auth/*, /api/user/*, /api/logs/*, /api/captcha/*) =====
  54. '^/api/(auth|user|logs|captcha|ticket)': {
  55. target: 'https://aqai.shudaodsj.com:22000/', // 后端认证服务地址
  56. changeOrigin: true,
  57. // 不重写路径,直接转发
  58. },
  59. // 业务 API 代理
  60. '/apiv1': {
  61. target: 'http://127.0.0.1:22000',
  62. changeOrigin: true,
  63. rewrite: (path) => path.replace(/^\/apiv1/, '/apiv1'),
  64. }
  65. }
  66. }
  67. })