From 9a138d260a53f56618754a14ede32004765ba7ba Mon Sep 17 00:00:00 2001
From: Ravi Rajput <ravi81rajput@gmail.com>
Date: Thu, 11 Apr 2024 18:57:48 +0530
Subject: [PATCH 1/2] Added config endpoint

---
 apps/web/app/config/route.ts |  8 ++++++++
 apps/web/app/layout.tsx      | 21 ++++++---------------
 2 files changed, 14 insertions(+), 15 deletions(-)
 create mode 100644 apps/web/app/config/route.ts

diff --git a/apps/web/app/config/route.ts b/apps/web/app/config/route.ts
new file mode 100644
index 00000000..5e4be63d
--- /dev/null
+++ b/apps/web/app/config/route.ts
@@ -0,0 +1,8 @@
+export const dynamic = "force-dynamic";
+
+export function GET(request: Request, response: Response) {
+    return Response.json({
+        posthog: process.env.Posthog_ID,
+        crisp: process.env.Crisp_ID,
+    });
+}
diff --git a/apps/web/app/layout.tsx b/apps/web/app/layout.tsx
index eb5d6394..86560032 100644
--- a/apps/web/app/layout.tsx
+++ b/apps/web/app/layout.tsx
@@ -17,41 +17,32 @@ export default async function RootLayout({
 }: {
     children: React.ReactNode;
 }) {
+    const response = await fetch(`${process.env.AUTH_URL}/config`);
+    const result = await response.json();
     return (
         <html lang="en">
             <head>
                 <Script strategy="lazyOnload" id="posthog-analytics">
                     {`
     !function(t,e){var o,n,p,r;e.__SV||(window.posthog=e,e._i=[],e.init=function(i,s,a){function g(t,e){var o=e.split(".");2==o.length&&(t=t[o[0]],e=o[1]),t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}}(p=t.createElement("script")).type="text/javascript",p.async=!0,p.src=s.api_host+"/static/array.js",(r=t.getElementsByTagName("script")[0]).parentNode.insertBefore(p,r);var u=e;for(void 0!==a?u=e[a]=[]:a="posthog",u.people=u.people||[],u.toString=function(t){var e="posthog";return"posthog"!==a&&(e+="."+a),t||(e+=" (stub)"),e},u.people.toString=function(){return u.toString(1)+".people (stub)"},o="capture identify alias people.set people.set_once set_config register register_once unregister opt_out_capturing has_opted_out_capturing opt_in_capturing reset isFeatureEnabled onFeatureFlags getFeatureFlag getFeatureFlagPayload reloadFeatureFlags group updateEarlyAccessFeatureEnrollment getEarlyAccessFeatures getActiveMatchingSurveys getSurveys onSessionId".split(" "),n=0;n<o.length;n++)g(u,o[n]);e._i.push([i,s,a])},e.__SV=1)}(document,window.posthog||[]);
-    posthog.init('phc_gUsiknwRdJTfxuwTvIXspsmHhg7idUnnoJ0zOHBs12d',{api_host:'https://app.posthog.com'})
+    posthog.init('${result.posthog}',{api_host:'https://app.posthog.com'})
             `}
                 </Script>
                 <Script strategy="lazyOnload" id="posthog-session-recording">
                     {`
                     !function(t,e){var o,n,p,r;e.__SV||(window.posthog=e,e._i=[],e.init=function(i,s,a){function g(t,e){var o=e.split(".");2==o.length&&(t=t[o[0]],e=o[1]),t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}}(p=t.createElement("script")).type="text/javascript",p.async=!0,p.src=s.api_host+"/static/array.js",(r=t.getElementsByTagName("script")[0]).parentNode.insertBefore(p,r);var u=e;for(void 0!==a?u=e[a]=[]:a="posthog",u.people=u.people||[],u.toString=function(t){var e="posthog";return"posthog"!==a&&(e+="."+a),t||(e+=" (stub)"),e},u.people.toString=function(){return u.toString(1)+".people (stub)"},o="capture identify alias people.set people.set_once set_config register register_once unregister opt_out_capturing has_opted_out_capturing opt_in_capturing reset isFeatureEnabled onFeatureFlags getFeatureFlag getFeatureFlagPayload reloadFeatureFlags group updateEarlyAccessFeatureEnrollment getEarlyAccessFeatures getActiveMatchingSurveys getSurveys onSessionId".split(" "),n=0;n<o.length;n++)g(u,o[n]);e._i.push([i,s,a])},e.__SV=1)}(document,window.posthog||[]);
-                    posthog.init('phc_gUsiknwRdJTfxuwTvIXspsmHhg7idUnnoJ0zOHBs12d',{api_host:'https://app.posthog.com'})
+                    posthog.init('${result.posthog}',{api_host:'https://app.posthog.com'})
                     `}
                 </Script>
                 <Script strategy="lazyOnload" id="posthog-survey">
                     {`
                     !function(t,e){var o,n,p,r;e.__SV||(window.posthog=e,e._i=[],e.init=function(i,s,a){function g(t,e){var o=e.split(".");2==o.length&&(t=t[o[0]],e=o[1]),t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}}(p=t.createElement("script")).type="text/javascript",p.async=!0,p.src=s.api_host+"/static/array.js",(r=t.getElementsByTagName("script")[0]).parentNode.insertBefore(p,r);var u=e;for(void 0!==a?u=e[a]=[]:a="posthog",u.people=u.people||[],u.toString=function(t){var e="posthog";return"posthog"!==a&&(e+="."+a),t||(e+=" (stub)"),e},u.people.toString=function(){return u.toString(1)+".people (stub)"},o="capture identify alias people.set people.set_once set_config register register_once unregister opt_out_capturing has_opted_out_capturing opt_in_capturing reset isFeatureEnabled onFeatureFlags getFeatureFlag getFeatureFlagPayload reloadFeatureFlags group updateEarlyAccessFeatureEnrollment getEarlyAccessFeatures getActiveMatchingSurveys getSurveys onSessionId".split(" "),n=0;n<o.length;n++)g(u,o[n]);e._i.push([i,s,a])},e.__SV=1)}(document,window.posthog||[]);
-                    posthog.init('phc_gUsiknwRdJTfxuwTvIXspsmHhg7idUnnoJ0zOHBs12d',{api_host:'https://app.posthog.com'})
-                    `}
-                </Script>
-                <Script strategy="lazyOnload" id="microsoft-clarity">
-                    {`
-                    if (!window.location.host.includes('localhost')) {
-                        (function(c,l,a,r,i,t,y){
-                            c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
-                            t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i;
-                            y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);
-                        })(window, document, "clarity", "script", "khzsjjff0s");
-                    }
+                    posthog.init('${result.posthog}',{api_host:'https://app.posthog.com'})
                     `}
                 </Script>
                 <Script strategy="lazyOnload" id="crisp-chat">
                     {`
-                    window.$crisp=[];window.CRISP_WEBSITE_ID="8048ca09-d44e-44a3-ad68-922fff5fd1fa";(function(){d=document;s=d.createElement("script");s.src="https://client.crisp.chat/l.js";s.async=1;d.getElementsByTagName("head")[0].appendChild(s);})();
+                    window.$crisp=[];window.CRISP_WEBSITE_ID="${result.crisp}";(function(){d=document;s=d.createElement("script");s.src="https://client.crisp.chat/l.js";s.async=1;d.getElementsByTagName("head")[0].appendChild(s);})();
                     `}
                 </Script>
             </head>

From 46e19c98c1ff6f4a85112089d4172debe7193d08 Mon Sep 17 00:00:00 2001
From: Ravi Rajput <ravi81rajput@gmail.com>
Date: Thu, 11 Apr 2024 19:25:14 +0530
Subject: [PATCH 2/2] Fixed environment variables name

---
 apps/web/app/config/route.ts | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/apps/web/app/config/route.ts b/apps/web/app/config/route.ts
index 5e4be63d..fd980f0c 100644
--- a/apps/web/app/config/route.ts
+++ b/apps/web/app/config/route.ts
@@ -2,7 +2,7 @@ export const dynamic = "force-dynamic";
 
 export function GET(request: Request, response: Response) {
     return Response.json({
-        posthog: process.env.Posthog_ID,
-        crisp: process.env.Crisp_ID,
+        posthog: process.env.POSTHOG_ID,
+        crisp: process.env.CRISP_ID,
     });
 }