next.config.mjs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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: "/:path((?!_next|agent|chat|favicon.ico).*)",
  49. destination: `http://${backendHost}:${backendPort}/:path*`,
  50. },
  51. ];
  52. }
  53. return [];
  54. },
  55. images: {
  56. remotePatterns: [
  57. {
  58. protocol: "http",
  59. hostname: "192.168.124.9",
  60. port: backendPort,
  61. pathname: "/uploads/**",
  62. },
  63. {
  64. protocol: "http",
  65. hostname: "localhost",
  66. port: backendPort,
  67. pathname: "/uploads/**",
  68. },
  69. {
  70. protocol: "http",
  71. hostname: "127.0.0.1",
  72. port: backendPort,
  73. pathname: "/uploads/**",
  74. },
  75. ],
  76. },
  77. };
  78. export default nextConfig;