From e8c2708c6368abcf460949965bbabf117e0f5543 Mon Sep 17 00:00:00 2001 From: ramnique <30795890+ramnique@users.noreply.github.com> Date: Mon, 10 Mar 2025 14:31:23 +0530 Subject: [PATCH] fix chat-widget bootstrap loading --- apps/chat_widget/app/api/bootstrap.js/route.ts | 16 ++++------------ .../bootstrap.template.js} | 0 2 files changed, 4 insertions(+), 12 deletions(-) rename apps/chat_widget/{app/api/bootstrap.js/bootstrap.js => public/bootstrap.template.js} (100%) diff --git a/apps/chat_widget/app/api/bootstrap.js/route.ts b/apps/chat_widget/app/api/bootstrap.js/route.ts index d2df0406..b59ec71f 100644 --- a/apps/chat_widget/app/api/bootstrap.js/route.ts +++ b/apps/chat_widget/app/api/bootstrap.js/route.ts @@ -1,21 +1,13 @@ -import { promises as fs } from 'fs'; -import path from 'path'; -import { fileURLToPath } from 'url'; - export const dynamic = 'force-dynamic' -const __dirname = path.dirname(fileURLToPath(import.meta.url)); - -// Read the file once when the module loads -const jsFileContents = fs.readFile( - path.join(__dirname, 'bootstrap.js'), - 'utf-8' -); +// Fetch template once when module loads +const templatePromise = fetch(process.env.CHAT_WIDGET_HOST + '/bootstrap.template.js') + .then(res => res.text()); export async function GET() { try { // Reuse the cached content - const template = await jsFileContents; + const template = await templatePromise; // Replace placeholder values with actual URLs const contents = template diff --git a/apps/chat_widget/app/api/bootstrap.js/bootstrap.js b/apps/chat_widget/public/bootstrap.template.js similarity index 100% rename from apps/chat_widget/app/api/bootstrap.js/bootstrap.js rename to apps/chat_widget/public/bootstrap.template.js