2023-06-07 15:47:21 +00:00
|
|
|
const mode = process.env.BUILD_MODE ?? "standalone";
|
|
|
|
console.log("[Next] build mode", mode);
|
2023-03-12 19:06:21 +00:00
|
|
|
|
2023-06-07 15:47:21 +00:00
|
|
|
/** @type {import('next').NextConfig} */
|
2023-03-12 19:21:48 +00:00
|
|
|
const nextConfig = {
|
2023-06-07 15:47:21 +00:00
|
|
|
webpack(config) {
|
|
|
|
config.module.rules.push({
|
|
|
|
test: /\.svg$/,
|
|
|
|
use: ["@svgr/webpack"],
|
|
|
|
});
|
|
|
|
|
|
|
|
return config;
|
|
|
|
},
|
|
|
|
output: mode,
|
2023-06-15 15:20:14 +00:00
|
|
|
images: {
|
|
|
|
unoptimized: mode === "export",
|
|
|
|
},
|
2023-06-07 15:47:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (mode !== "export") {
|
2023-06-13 16:37:42 +00:00
|
|
|
nextConfig.headers = async () => {
|
|
|
|
return [
|
|
|
|
{
|
2023-06-14 16:28:47 +00:00
|
|
|
source: "/api/:path*",
|
2023-06-13 16:37:42 +00:00
|
|
|
headers: [
|
|
|
|
{ key: "Access-Control-Allow-Credentials", value: "true" },
|
|
|
|
{ key: "Access-Control-Allow-Origin", value: "*" },
|
|
|
|
{
|
|
|
|
key: "Access-Control-Allow-Methods",
|
2023-06-14 16:28:47 +00:00
|
|
|
value: "*",
|
2023-06-13 16:37:42 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "Access-Control-Allow-Headers",
|
2023-06-14 16:28:47 +00:00
|
|
|
value: "*",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "Access-Control-Max-Age",
|
|
|
|
value: "86400",
|
2023-06-13 16:37:42 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2023-06-07 15:47:21 +00:00
|
|
|
nextConfig.rewrites = async () => {
|
2023-05-08 16:39:00 +00:00
|
|
|
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-08 16:39:00 +00:00
|
|
|
];
|
2023-05-03 15:49:33 +00:00
|
|
|
|
|
|
|
const apiUrl = process.env.API_URL;
|
|
|
|
if (apiUrl) {
|
|
|
|
console.log("[Next] using api url ", apiUrl);
|
|
|
|
ret.push({
|
|
|
|
source: "/api/:path*",
|
|
|
|
destination: `${apiUrl}/:path*`,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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-06-07 15:47:21 +00:00
|
|
|
};
|
|
|
|
}
|
2023-03-09 17:01:40 +00:00
|
|
|
|
2023-05-03 15:08:37 +00:00
|
|
|
export default nextConfig;
|