next.config.mjs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import webpack from "webpack";
  2. const mode = process.env.BUILD_MODE ?? "standalone";
  3. const disableChunk = !!process.env.DISABLE_CHUNK || mode === "standalone";
  4. /** @type {import('next').NextConfig} */
  5. const nextConfig = {
  6. webpack(config) {
  7. config.module.rules.push({
  8. test: /\.svg$/,
  9. use: ["@svgr/webpack"],
  10. });
  11. if (disableChunk) {
  12. config.plugins.push(
  13. new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 1 }),
  14. );
  15. }
  16. config.resolve.fallback = {
  17. child_process: false,
  18. };
  19. return config;
  20. },
  21. output: mode,
  22. images: {
  23. unoptimized: mode === "standalone",
  24. },
  25. experimental: {
  26. forceSwcTransforms: true,
  27. },
  28. reactStrictMode: false,// 关闭模式
  29. };
  30. const CorsHeaders = [
  31. { key: "Access-Control-Allow-Credentials", value: "true" },
  32. { key: "Access-Control-Allow-Origin", value: "*" },
  33. {
  34. key: "Access-Control-Allow-Methods",
  35. value: "*",
  36. },
  37. {
  38. key: "Access-Control-Allow-Headers",
  39. value: "*",
  40. },
  41. {
  42. key: "Access-Control-Max-Age",
  43. value: "86400",
  44. },
  45. ];
  46. if (mode !== "export") {
  47. nextConfig.headers = async () => {
  48. return [
  49. {
  50. source: "/api/:path*",
  51. headers: CorsHeaders,
  52. },
  53. ];
  54. };
  55. nextConfig.rewrites = async () => {
  56. const ret = [
  57. {
  58. source: "/api/proxy/v1/:path*",
  59. destination: "https://api.openai.com/v1/:path*",
  60. },
  61. {
  62. source: "/api/proxy/azure/:resource_name/deployments/:deploy_name/:path*",
  63. destination: "https://:resource_name.openai.azure.com/openai/deployments/:deploy_name/:path*",
  64. },
  65. {
  66. source: "/api/proxy/google/:path*",
  67. destination: "https://generativelanguage.googleapis.com/:path*",
  68. },
  69. {
  70. source: "/api/proxy/openai/:path*",
  71. destination: "https://api.openai.com/:path*",
  72. },
  73. {
  74. source: "/api/proxy/anthropic/:path*",
  75. destination: "https://api.anthropic.com/:path*",
  76. },
  77. {
  78. source: "/google-fonts/:path*",
  79. destination: "https://fonts.googleapis.com/:path*",
  80. },
  81. {
  82. source: "/sharegpt",
  83. destination: "https://sharegpt.com/api/conversations",
  84. },
  85. {
  86. source: "/bigmodel-api/:path*",
  87. destination: "http://192.168.3.123:8091/:path*",
  88. },
  89. {
  90. source: "/deepseek-api/:path*",
  91. // destination: "http://xia0miduo.gicp.net:8000/:path*",
  92. destination: "http://192.168.3.209:18078/:path*",
  93. },
  94. ];
  95. return {
  96. beforeFiles: ret,
  97. };
  98. };
  99. }
  100. export default nextConfig;