next.config.mjs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. typescript:{
  29. ignoreBuildErrors: true,
  30. },
  31. eslint: {
  32. ignoreDuringBuilds: true,
  33. },
  34. };
  35. const CorsHeaders = [
  36. { key: "Access-Control-Allow-Credentials", value: "true" },
  37. { key: "Access-Control-Allow-Origin", value: "*" },
  38. {
  39. key: "Access-Control-Allow-Methods",
  40. value: "*",
  41. },
  42. {
  43. key: "Access-Control-Allow-Headers",
  44. value: "*",
  45. },
  46. {
  47. key: "Access-Control-Max-Age",
  48. value: "86400",
  49. },
  50. ];
  51. if (mode !== "export") {
  52. nextConfig.headers = async () => {
  53. return [
  54. {
  55. source: "/api/:path*",
  56. headers: CorsHeaders,
  57. },
  58. ];
  59. };
  60. nextConfig.rewrites = async () => {
  61. const ret = [
  62. {
  63. source: "/api/proxy/v1/:path*",
  64. destination: "https://api.openai.com/v1/:path*",
  65. },
  66. {
  67. source: "/api/proxy/azure/:resource_name/deployments/:deploy_name/:path*",
  68. destination: "https://:resource_name.openai.azure.com/openai/deployments/:deploy_name/:path*",
  69. },
  70. {
  71. source: "/api/proxy/google/:path*",
  72. destination: "https://generativelanguage.googleapis.com/:path*",
  73. },
  74. {
  75. source: "/api/proxy/openai/:path*",
  76. destination: "https://api.openai.com/:path*",
  77. },
  78. {
  79. source: "/api/proxy/anthropic/:path*",
  80. destination: "https://api.anthropic.com/:path*",
  81. },
  82. {
  83. source: "/google-fonts/:path*",
  84. destination: "https://fonts.googleapis.com/:path*",
  85. },
  86. {
  87. source: "/sharegpt",
  88. destination: "https://sharegpt.com/api/conversations",
  89. },
  90. {
  91. source: "/bigmodel-api/:path*",
  92. // destination: "http://192.168.3.3:8091/:path*",
  93. // destination: "http://xia0miduo.gicp.net:9080/:path*",
  94. // destination: "http://192.168.110.13:9080/:path*", // 公司
  95. destination: "http://10.1.14.17:9080/:path*", // 公司
  96. },
  97. {
  98. source: "/deepseek-api/:path*",
  99. destination: "http://xia0miduo.gicp.net:18078/:path*",
  100. },
  101. ];
  102. return {
  103. beforeFiles: ret,
  104. };
  105. };
  106. }
  107. export default nextConfig;