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