From 119af4384e8a5485e71606b58e0b37ce51f44bd2 Mon Sep 17 00:00:00 2001 From: Laurie Voss <github@seldo.com> Date: Sun, 19 Nov 2023 15:55:27 -0800 Subject: [PATCH] next.config.js has to be different for express/python backends --- create-app.ts | 2 +- templates/index.ts | 21 +++++++++++++++++++ templates/types.ts | 1 + .../{next.config.js => next.config.app.js} | 0 .../types/simple/nextjs/next.config.static.js | 13 ++++++++++++ .../{next.config.js => next.config.app.js} | 0 .../streaming/nextjs/next.config.static.js | 13 ++++++++++++ 7 files changed, 49 insertions(+), 1 deletion(-) rename templates/types/simple/nextjs/{next.config.js => next.config.app.js} (100%) create mode 100644 templates/types/simple/nextjs/next.config.static.js rename templates/types/streaming/nextjs/{next.config.js => next.config.app.js} (100%) create mode 100644 templates/types/streaming/nextjs/next.config.static.js diff --git a/create-app.ts b/create-app.ts index 70d7b40d..25c47dbd 100644 --- a/create-app.ts +++ b/create-app.ts @@ -88,7 +88,7 @@ export async function createApp({ path.join(root, "README.md"), ); } else { - await installTemplate({ ...args, backend: true }); + await installTemplate({ ...args, backend: true, forBackend: framework }); } process.chdir(root); diff --git a/templates/index.ts b/templates/index.ts index d6e5cd61..a9f0998e 100644 --- a/templates/index.ts +++ b/templates/index.ts @@ -103,6 +103,7 @@ const installTSTemplate = async ({ ui, eslint, customApiPath, + forBackend, }: InstallTemplateArgs) => { console.log(bold(`Using ${packageManager}.`)); @@ -120,6 +121,26 @@ const installTSTemplate = async ({ rename, }); + /** + * If the backend is next.js, rename next.config.app.js to next.config.js + * If not, rename next.config.static.js to next.config.js + */ + if (framework == "nextjs" && forBackend === "nextjs") { + const nextConfigAppPath = path.join(root, "next.config.app.js"); + const nextConfigPath = path.join(root, "next.config.js"); + await fs.rename(nextConfigAppPath, nextConfigPath); + // delete next.config.static.js + const nextConfigStaticPath = path.join(root, "next.config.static.js"); + await fs.rm(nextConfigStaticPath); + } else if (framework == "nextjs" && typeof forBackend === "undefined") { + const nextConfigStaticPath = path.join(root, "next.config.static.js"); + const nextConfigPath = path.join(root, "next.config.js"); + await fs.rename(nextConfigStaticPath, nextConfigPath); + // delete next.config.app.js + const nextConfigAppPath = path.join(root, "next.config.app.js"); + await fs.rm(nextConfigAppPath); + } + /** * Copy the selected chat engine files to the target directory and reference it. */ diff --git a/templates/types.ts b/templates/types.ts index 4bcaf5c7..926dddd5 100644 --- a/templates/types.ts +++ b/templates/types.ts @@ -17,4 +17,5 @@ export interface InstallTemplateArgs { eslint: boolean; customApiPath?: string; openAIKey?: string; + forBackend?: string; } diff --git a/templates/types/simple/nextjs/next.config.js b/templates/types/simple/nextjs/next.config.app.js similarity index 100% rename from templates/types/simple/nextjs/next.config.js rename to templates/types/simple/nextjs/next.config.app.js diff --git a/templates/types/simple/nextjs/next.config.static.js b/templates/types/simple/nextjs/next.config.static.js new file mode 100644 index 00000000..166b3e67 --- /dev/null +++ b/templates/types/simple/nextjs/next.config.static.js @@ -0,0 +1,13 @@ +/** @type {import('next').NextConfig} */ +const nextConfig = { + output: "export", + images: { unoptimized: true }, + experimental: { + serverComponentsExternalPackages: ["llamaindex"], + outputFileTracingIncludes: { + "/*": ["./cache/**/*"], + }, + }, +}; + +module.exports = nextConfig; diff --git a/templates/types/streaming/nextjs/next.config.js b/templates/types/streaming/nextjs/next.config.app.js similarity index 100% rename from templates/types/streaming/nextjs/next.config.js rename to templates/types/streaming/nextjs/next.config.app.js diff --git a/templates/types/streaming/nextjs/next.config.static.js b/templates/types/streaming/nextjs/next.config.static.js new file mode 100644 index 00000000..166b3e67 --- /dev/null +++ b/templates/types/streaming/nextjs/next.config.static.js @@ -0,0 +1,13 @@ +/** @type {import('next').NextConfig} */ +const nextConfig = { + output: "export", + images: { unoptimized: true }, + experimental: { + serverComponentsExternalPackages: ["llamaindex"], + outputFileTracingIncludes: { + "/*": ["./cache/**/*"], + }, + }, +}; + +module.exports = nextConfig; -- GitLab