diff --git a/create-app.ts b/create-app.ts
index 70d7b40dc437cae91c7ee152719abd6e0075cae4..25c47dbd0bcd72a01625c2fadd0b04fda7da22be 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 d6e5cd61fd75351abde00cebb7d07d0c7a6acb1f..a9f0998eb2315ee1e2166904e548d14db7fb5b00 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 4bcaf5c7bb8464641e964e4fff74c36393f47fdb..926dddd5d97899e0886f6c2fc788906d168363e4 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/express/gitignore b/templates/types/simple/express/gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..15c3d3d576346a73d81d193ffc345f814cc291ca
--- /dev/null
+++ b/templates/types/simple/express/gitignore
@@ -0,0 +1,2 @@
+# local env files
+.env
diff --git a/templates/types/simple/express/index.ts b/templates/types/simple/express/index.ts
index 90e67278de93c1189341e432776d29f03108319b..daf5d8b6e82599243a1becc1d8e85c0de769e9dd 100644
--- a/templates/types/simple/express/index.ts
+++ b/templates/types/simple/express/index.ts
@@ -8,9 +8,21 @@ const port = 8000;
 
 const env = process.env["NODE_ENV"];
 const isDevelopment = !env || env === "development";
+const prodCorsOrigin = process.env["PROD_CORS_ORIGIN"];
+
 if (isDevelopment) {
   console.warn("Running in development mode - allowing CORS for all origins");
   app.use(cors());
+} else if (prodCorsOrigin) {
+  console.log(
+    `Running in production mode - allowing CORS for domain: ${prodCorsOrigin}`,
+  );
+  const corsOptions = {
+    origin: prodCorsOrigin, // Restrict to production domain
+  };
+  app.use(cors(corsOptions));
+} else {
+  console.warn("Production CORS origin not set, defaulting to no CORS.");
 }
 
 app.use(express.text());
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 0000000000000000000000000000000000000000..166b3e67d75ddc6d594b1c3d0960cc51f54b13b9
--- /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/express/gitignore b/templates/types/streaming/express/gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..15c3d3d576346a73d81d193ffc345f814cc291ca
--- /dev/null
+++ b/templates/types/streaming/express/gitignore
@@ -0,0 +1,2 @@
+# local env files
+.env
diff --git a/templates/types/streaming/express/index.ts b/templates/types/streaming/express/index.ts
index 90e67278de93c1189341e432776d29f03108319b..daf5d8b6e82599243a1becc1d8e85c0de769e9dd 100644
--- a/templates/types/streaming/express/index.ts
+++ b/templates/types/streaming/express/index.ts
@@ -8,9 +8,21 @@ const port = 8000;
 
 const env = process.env["NODE_ENV"];
 const isDevelopment = !env || env === "development";
+const prodCorsOrigin = process.env["PROD_CORS_ORIGIN"];
+
 if (isDevelopment) {
   console.warn("Running in development mode - allowing CORS for all origins");
   app.use(cors());
+} else if (prodCorsOrigin) {
+  console.log(
+    `Running in production mode - allowing CORS for domain: ${prodCorsOrigin}`,
+  );
+  const corsOptions = {
+    origin: prodCorsOrigin, // Restrict to production domain
+  };
+  app.use(cors(corsOptions));
+} else {
+  console.warn("Production CORS origin not set, defaulting to no CORS.");
 }
 
 app.use(express.text());
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 0000000000000000000000000000000000000000..166b3e67d75ddc6d594b1c3d0960cc51f54b13b9
--- /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;