next.config.mjs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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: "/: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: "GET,OPTIONS,PATCH,DELETE,POST,PUT",
  25. },
  26. {
  27. key: "Access-Control-Allow-Headers",
  28. value:
  29. "X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version",
  30. },
  31. ],
  32. },
  33. ];
  34. };
  35. nextConfig.rewrites = async () => {
  36. const ret = [
  37. {
  38. source: "/api/proxy/:path*",
  39. destination: "https://api.openai.com/:path*",
  40. },
  41. {
  42. source: "/google-fonts/:path*",
  43. destination: "https://fonts.googleapis.com/:path*",
  44. },
  45. {
  46. source: "/sharegpt",
  47. destination: "https://sharegpt.com/api/conversations",
  48. },
  49. ];
  50. const apiUrl = process.env.API_URL;
  51. if (apiUrl) {
  52. console.log("[Next] using api url ", apiUrl);
  53. ret.push({
  54. source: "/api/:path*",
  55. destination: `${apiUrl}/:path*`,
  56. });
  57. }
  58. return {
  59. beforeFiles: ret,
  60. };
  61. };
  62. }
  63. export default nextConfig;