ChatGPT-Next-Web/next.config.mjs

88 lines
1.7 KiB
JavaScript
Raw Permalink Normal View History

import webpack from "webpack";
const mode = process.env.BUILD_MODE ?? "standalone";
console.log("[Next] build mode", mode);
2023-03-12 19:06:21 +00:00
const disableChunk = !!process.env.DISABLE_CHUNK || mode === "export";
console.log("[Next] build with chunk: ", !disableChunk);
/** @type {import('next').NextConfig} */
2023-03-12 19:21:48 +00:00
const nextConfig = {
webpack(config) {
config.module.rules.push({
test: /\.svg$/,
use: ["@svgr/webpack"],
});
if (disableChunk) {
config.plugins.push(
new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 1 }),
);
}
config.resolve.fallback = {
child_process: false,
};
return config;
},
output: mode,
2023-06-15 15:20:14 +00:00
images: {
unoptimized: mode === "export",
},
2023-07-16 08:32:22 +00:00
experimental: {
forceSwcTransforms: true,
},
};
2023-09-12 18:51:02 +00:00
const CorsHeaders = [
{ key: "Access-Control-Allow-Credentials", value: "true" },
{ key: "Access-Control-Allow-Origin", value: "*" },
{
key: "Access-Control-Allow-Methods",
value: "*",
},
{
key: "Access-Control-Allow-Headers",
value: "*",
},
{
key: "Access-Control-Max-Age",
value: "86400",
},
];
if (mode !== "export") {
nextConfig.headers = async () => {
return [
{
2023-06-14 16:28:47 +00:00
source: "/api/:path*",
2023-09-12 18:51:02 +00:00
headers: CorsHeaders,
},
];
};
nextConfig.rewrites = async () => {
const ret = [
{
source: "/api/proxy/:path*",
destination: "https://api.openai.com/:path*",
},
2023-05-14 15:25:22 +00:00
{
source: "/google-fonts/:path*",
destination: "https://fonts.googleapis.com/:path*",
},
2023-05-24 17:04:37 +00:00
{
source: "/sharegpt",
destination: "https://sharegpt.com/api/conversations",
},
];
2023-05-04 14:18:03 +00:00
return {
2023-05-05 14:49:41 +00:00
beforeFiles: ret,
2023-05-04 14:18:03 +00:00
};
};
}
2023-03-09 17:01:40 +00:00
2023-05-03 15:08:37 +00:00
export default nextConfig;