From 159774a023a936246ef2d7505de90ba927864e0f Mon Sep 17 00:00:00 2001 From: Arek Nawo Date: Thu, 6 Jun 2024 13:48:56 +0200 Subject: [PATCH] feat: Conditional analytics --- apps/backend/app/src/app.ts | 1 + apps/web/index.html | 12 ++++++++++++ apps/web/vite.config.mts | 8 +++++--- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/apps/backend/app/src/app.ts b/apps/backend/app/src/app.ts index 65f8f347..807449b0 100644 --- a/apps/backend/app/src/app.ts +++ b/apps/backend/app/src/app.ts @@ -14,6 +14,7 @@ import path from "path"; const appService = createPlugin(async (fastify) => { const renderPage = async (reply: FastifyReply): Promise => { return reply.header("X-Frame-Options", "SAMEORIGIN").view("index.html", { + VRITE_CLOUD: process.env.VRITE_CLOUD, PUBLIC_APP_URL: fastify.config.PUBLIC_APP_URL, PUBLIC_API_URL: fastify.config.PUBLIC_API_URL, PUBLIC_COLLAB_URL: fastify.config.PUBLIC_COLLAB_URL, diff --git a/apps/web/index.html b/apps/web/index.html index 0df69445..4c110374 100644 --- a/apps/web/index.html +++ b/apps/web/index.html @@ -66,6 +66,18 @@ } } + {{#if VRITE_CLOUD}} + + + {{/if}} diff --git a/apps/web/vite.config.mts b/apps/web/vite.config.mts index a6f2b278..2e7167b8 100644 --- a/apps/web/vite.config.mts +++ b/apps/web/vite.config.mts @@ -13,9 +13,11 @@ export default defineConfig(async ({ mode }) => { plugins.push({ name: "html-transform", transformIndexHtml(html: string) { - return html.replace(/{{(PUBLIC_.+?)}}/g, (_match, name) => { - return env[name]; - }); + return html + .replace(/{{(PUBLIC_.+?)}}/g, (_match, name) => { + return env[name]; + }) + .replace(/{{#if VRITE_CLOUD}}(?:.|\n)+?{{\/if}}/g, ""); } }); }