next.config.mjs 2.4 KB

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