next.config.mjs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /**
  2. * 生产用 Next 配置(纯 JS,运行时无需 TypeScript)
  3. * 与 next.config.ts 逻辑一致,供 Docker 生产镜像使用,避免 next start 触发 npm install
  4. */
  5. // 开发时代理目标端口(统一从根目录 .env 读取 NEXT_PUBLIC_BACKEND_*)
  6. const backendPort = process.env.NEXT_PUBLIC_BACKEND_PORT || "8080";
  7. const backendHost = process.env.NEXT_PUBLIC_BACKEND_HOST || "localhost";
  8. /** @type {import('next').NextConfig} */
  9. const nextConfig = {
  10. async rewrites() {
  11. if (process.env.NODE_ENV === "development") {
  12. return [
  13. // 形态2(同域 /api)在本地开发的兜底:把 /api/* 代理到后端 /api/*
  14. {
  15. source: "/api/:path*",
  16. destination: `http://${backendHost}:${backendPort}/api/:path*`,
  17. },
  18. {
  19. source: "/agent/profile/:path*",
  20. destination: `http://${backendHost}:${backendPort}/agent/profile/:path*`,
  21. },
  22. {
  23. source: "/agent/avatar/:path*",
  24. destination: `http://${backendHost}:${backendPort}/agent/avatar/:path*`,
  25. },
  26. {
  27. source: "/agent/embedding-config",
  28. destination: `http://${backendHost}:${backendPort}/agent/embedding-config`,
  29. },
  30. {
  31. source: "/agent/ai-config/:path*",
  32. destination: `http://${backendHost}:${backendPort}/agent/ai-config/:path*`,
  33. },
  34. {
  35. // 数据报表 API(后端 gin 路由在 /agent/analytics/summary)
  36. source: "/agent/analytics/summary",
  37. destination: `http://${backendHost}:${backendPort}/agent/analytics/summary`,
  38. },
  39. {
  40. source: "/agent/logs/api",
  41. destination: `http://${backendHost}:${backendPort}/agent/logs/api`,
  42. },
  43. {
  44. source: "/agent/logs/frontend",
  45. destination: `http://${backendHost}:${backendPort}/agent/logs/frontend`,
  46. },
  47. {
  48. source: "/agent/logs/min-level",
  49. destination: `http://${backendHost}:${backendPort}/agent/logs/min-level`,
  50. },
  51. {
  52. source: "/:path((?!_next|agent|chat|favicon.ico).*)",
  53. destination: `http://${backendHost}:${backendPort}/:path*`,
  54. },
  55. ];
  56. }
  57. return [];
  58. },
  59. images: {
  60. remotePatterns: [
  61. {
  62. protocol: "http",
  63. hostname: "192.168.124.9",
  64. port: backendPort,
  65. pathname: "/uploads/**",
  66. },
  67. {
  68. protocol: "http",
  69. hostname: "localhost",
  70. port: backendPort,
  71. pathname: "/uploads/**",
  72. },
  73. {
  74. protocol: "http",
  75. hostname: "127.0.0.1",
  76. port: backendPort,
  77. pathname: "/uploads/**",
  78. },
  79. ],
  80. },
  81. };
  82. export default nextConfig;