ChatGPT-Next-Web/next.config.mjs

110 lines
2.6 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-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 = [
// adjust for previous version directly using "/api/proxy/" as proxy base route
// {
// source: "/api/proxy/v1/:path*",
// destination: "https://api.openai.com/v1/:path*",
// },
2024-07-05 19:59:45 +08:00
{
// https://{resource_name}.openai.azure.com/openai/deployments/{deploy_name}/chat/completions
source: "/api/proxy/azure/:resource_name/deployments/:deploy_name/:path*",
destination: "https://:resource_name.openai.azure.com/openai/deployments/:deploy_name/:path*",
},
{
source: "/api/proxy/google/:path*",
destination: "https://generativelanguage.googleapis.com/:path*",
},
{
source: "/api/proxy/openai/:path*",
destination: "https://api.openai.com/:path*",
},
2024-04-08 13:41:02 +08:00
{
source: "/api/proxy/anthropic/:path*",
destination: "https://api.anthropic.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",
},
{
source: "/api/proxy/alibaba/:path*",
destination: "https://dashscope.aliyuncs.com/api/:path*",
},
];
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;