next.config.mjs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**
  2. * 生产用 Next 配置(纯 JS,运行时无需 TypeScript)
  3. * 与 next.config.ts 逻辑一致,供 Docker 生产镜像使用,避免 next start 触发 npm install
  4. */
  5. const backendPort = process.env.NEXT_PUBLIC_BACKEND_PORT || "8080";
  6. const backendHost = process.env.NEXT_PUBLIC_BACKEND_HOST || "localhost";
  7. /** @type {import('next').NextConfig} */
  8. const nextConfig = {
  9. async rewrites() {
  10. if (process.env.NODE_ENV === "development") {
  11. return [
  12. {
  13. source: "/agent/profile/:path*",
  14. destination: `http://${backendHost}:${backendPort}/agent/profile/:path*`,
  15. },
  16. {
  17. source: "/agent/avatar/:path*",
  18. destination: `http://${backendHost}:${backendPort}/agent/avatar/:path*`,
  19. },
  20. {
  21. source: "/agent/embedding-config",
  22. destination: `http://${backendHost}:${backendPort}/agent/embedding-config`,
  23. },
  24. {
  25. source: "/agent/ai-config/:path*",
  26. destination: `http://${backendHost}:${backendPort}/agent/ai-config/:path*`,
  27. },
  28. {
  29. source: "/:path((?!_next|agent|chat|favicon.ico).*)",
  30. destination: `http://${backendHost}:${backendPort}/:path*`,
  31. },
  32. ];
  33. }
  34. return [];
  35. },
  36. images: {
  37. remotePatterns: [
  38. {
  39. protocol: "http",
  40. hostname: "192.168.124.9",
  41. port: backendPort,
  42. pathname: "/uploads/**",
  43. },
  44. {
  45. protocol: "http",
  46. hostname: "localhost",
  47. port: backendPort,
  48. pathname: "/uploads/**",
  49. },
  50. {
  51. protocol: "http",
  52. hostname: "127.0.0.1",
  53. port: backendPort,
  54. pathname: "/uploads/**",
  55. },
  56. ],
  57. },
  58. };
  59. export default nextConfig;