next.config.mjs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. const mode = process.env.BUILD_MODE ?? "standalone";
  2. console.log("[Next] build mode", mode);
  3. /** @type {import('next').NextConfig} */
  4. const nextConfig = {
  5. webpack(config) {
  6. config.module.rules.push({
  7. test: /\.svg$/,
  8. use: ["@svgr/webpack"],
  9. });
  10. return config;
  11. },
  12. output: mode,
  13. };
  14. if (mode !== "export") {
  15. nextConfig.rewrites = async () => {
  16. const ret = [
  17. {
  18. source: "/api/proxy/:path*",
  19. destination: "https://api.openai.com/:path*",
  20. },
  21. {
  22. source: "/google-fonts/:path*",
  23. destination: "https://fonts.googleapis.com/:path*",
  24. },
  25. {
  26. source: "/sharegpt",
  27. destination: "https://sharegpt.com/api/conversations",
  28. },
  29. ];
  30. const apiUrl = process.env.API_URL;
  31. if (apiUrl) {
  32. console.log("[Next] using api url ", apiUrl);
  33. ret.push({
  34. source: "/api/:path*",
  35. destination: `${apiUrl}/:path*`,
  36. });
  37. }
  38. return {
  39. beforeFiles: ret,
  40. };
  41. };
  42. }
  43. export default nextConfig;