ChatGPT-Next-Web/next.config.mjs

88 lines
1.7 KiB
JavaScript
Raw Normal View History

import webpack from "webpack";
const mode = process.env.BUILD_MODE ?? "standalone";
console.log("[Next] build mode", mode);
2023-03-13 03:06:21 +08:00
const disableChunk = !!process.env.DISABLE_CHUNK || mode === "export";
console.log("[Next] build with chunk: ", !disableChunk);
/** @type {import('next').NextConfig} */
2023-03-13 03:21:48 +08: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 23:20:14 +08:00
images: {
unoptimized: mode === "export",
},
2023-07-16 16:32:22 +08:00
experimental: {
forceSwcTransforms: true,
},
};
2023-09-13 02:51:02 +08: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-15 00:28:47 +08:00
source: "/api/:path*",
2023-09-13 02:51:02 +08:00
headers: CorsHeaders,
},
];
};
nextConfig.rewrites = async () => {
const ret = [
{
source: "/api/proxy/:path*",
destination: "https://api.openai.com/:path*",
},
2023-05-14 23:25:22 +08:00
{
source: "/google-fonts/:path*",
destination: "https://fonts.googleapis.com/:path*",
},
2023-05-25 01:04:37 +08:00
{
source: "/sharegpt",
destination: "https://sharegpt.com/api/conversations",
},
];
2023-05-04 22:18:03 +08:00
return {
2023-05-05 22:49:41 +08:00
beforeFiles: ret,
2023-05-04 22:18:03 +08:00
};
};
}
2023-03-10 01:01:40 +08:00
2023-05-03 23:08:37 +08:00
export default nextConfig;