2023-06-29 23:28:29 +08:00
|
|
|
import webpack from "webpack";
|
|
|
|
|
2023-06-07 23:47:21 +08:00
|
|
|
const mode = process.env.BUILD_MODE ?? "standalone";
|
|
|
|
console.log("[Next] build mode", mode);
|
2023-03-13 03:06:21 +08:00
|
|
|
|
2023-06-29 23:28:29 +08:00
|
|
|
const disableChunk = !!process.env.DISABLE_CHUNK || mode === "export";
|
|
|
|
console.log("[Next] build with chunk: ", !disableChunk);
|
|
|
|
|
2023-06-07 23:47:21 +08:00
|
|
|
/** @type {import('next').NextConfig} */
|
2023-03-13 03:21:48 +08:00
|
|
|
const nextConfig = {
|
2023-06-07 23:47:21 +08:00
|
|
|
webpack(config) {
|
|
|
|
config.module.rules.push({
|
|
|
|
test: /\.svg$/,
|
|
|
|
use: ["@svgr/webpack"],
|
|
|
|
});
|
|
|
|
|
2023-06-29 23:28:29 +08:00
|
|
|
if (disableChunk) {
|
|
|
|
config.plugins.push(
|
|
|
|
new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 1 }),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-07-09 22:18:48 +08:00
|
|
|
config.resolve.fallback = {
|
|
|
|
child_process: false,
|
|
|
|
};
|
|
|
|
|
2023-06-07 23:47:21 +08:00
|
|
|
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-06-07 23:47:21 +08:00
|
|
|
};
|
|
|
|
|
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",
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2023-06-07 23:47:21 +08:00
|
|
|
if (mode !== "export") {
|
2023-06-14 00:37:42 +08:00
|
|
|
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,
|
2023-06-14 00:37:42 +08:00
|
|
|
},
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2023-06-07 23:47:21 +08:00
|
|
|
nextConfig.rewrites = async () => {
|
2023-05-09 00:39:00 +08:00
|
|
|
const ret = [
|
2024-02-20 17:59:59 +08:00
|
|
|
// adjust for previous version directly using "/api/proxy/" as proxy base route
|
2024-09-05 13:51:22 +08:00
|
|
|
// {
|
|
|
|
// 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*",
|
|
|
|
},
|
2024-02-07 13:17:11 +08:00
|
|
|
{
|
|
|
|
source: "/api/proxy/google/:path*",
|
|
|
|
destination: "https://generativelanguage.googleapis.com/:path*",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
source: "/api/proxy/openai/:path*",
|
2023-05-09 00:39:00 +08:00
|
|
|
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",
|
|
|
|
},
|
2024-10-30 16:30:01 +08:00
|
|
|
{
|
|
|
|
source: "/api/proxy/alibaba/:path*",
|
|
|
|
destination: "https://dashscope.aliyuncs.com/api/:path*",
|
|
|
|
},
|
2023-05-09 00:39:00 +08:00
|
|
|
];
|
2024-10-30 16:30:01 +08:00
|
|
|
|
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-06-07 23:47:21 +08:00
|
|
|
};
|
|
|
|
}
|
2023-03-10 01:01:40 +08:00
|
|
|
|
2023-05-03 23:08:37 +08:00
|
|
|
export default nextConfig;
|