next.config.mjs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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.headers = async () => {
  16. return [
  17. {
  18. source: "/api/:path*",
  19. headers: [
  20. { key: "Access-Control-Allow-Credentials", value: "true" },
  21. { key: "Access-Control-Allow-Origin", value: "*" },
  22. {
  23. key: "Access-Control-Allow-Methods",
  24. value: "*",
  25. },
  26. {
  27. key: "Access-Control-Allow-Headers",
  28. value: "*",
  29. },
  30. {
  31. key: "Access-Control-Max-Age",
  32. value: "86400",
  33. },
  34. ],
  35. },
  36. ];
  37. };
  38. nextConfig.rewrites = async () => {
  39. const ret = [
  40. {
  41. source: "/api/proxy/:path*",
  42. destination: "https://api.openai.com/:path*",
  43. },
  44. {
  45. source: "/google-fonts/:path*",
  46. destination: "https://fonts.googleapis.com/:path*",
  47. },
  48. {
  49. source: "/sharegpt",
  50. destination: "https://sharegpt.com/api/conversations",
  51. },
  52. ];
  53. const apiUrl = process.env.API_URL;
  54. if (apiUrl) {
  55. console.log("[Next] using api url ", apiUrl);
  56. ret.push({
  57. source: "/api/:path*",
  58. destination: `${apiUrl}/:path*`,
  59. });
  60. }
  61. return {
  62. beforeFiles: ret,
  63. };
  64. };
  65. }
  66. export default nextConfig;