vite.config.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { defineConfig } from 'vite'
  2. import react from '@vitejs/plugin-react'
  3. // 后端运行在 8080,前端开发期通过代理避免跨域
  4. const PROXY_TARGET = 'https://api-internal.piaoquantv.com'
  5. // const PROXY_TARGET = 'http://localhost:8080'
  6. export default defineConfig({
  7. plugins: [react()],
  8. base: '/content-similarity-recall/', // CDN 部署路径
  9. server: {
  10. port: 5173,
  11. host: true,
  12. proxy: {
  13. '/videoVector': {
  14. target: PROXY_TARGET,
  15. changeOrigin: true,
  16. secure: false,
  17. configure: (proxy) => {
  18. proxy.on('error', (err, req) => {
  19. // 把 AggregateError.errors 全部展开, 看每个 IP 的真实失败原因
  20. const inner = (err as any)?.errors
  21. // eslint-disable-next-line no-console
  22. console.error('[proxy error]', req?.method, req?.url,
  23. '\n host:', PROXY_TARGET,
  24. '\n name:', err?.name,
  25. '\n code:', (err as any)?.code,
  26. '\n msg:', err?.message,
  27. '\n inner:', Array.isArray(inner)
  28. ? inner.map((e: any) => `${e?.code}@${e?.address}:${e?.port} ${e?.message}`).join(' | ')
  29. : 'none')
  30. })
  31. proxy.on('proxyReq', (_pReq, req) => {
  32. // eslint-disable-next-line no-console
  33. console.log('[proxy req]', req?.method, req?.url, '→', PROXY_TARGET)
  34. })
  35. },
  36. },
  37. },
  38. },
  39. })