From d775a61c9501b723a72d9548a1b17279a093b1ed Mon Sep 17 00:00:00 2001 From: Philip Okugbe <16838612+Philipinho@users.noreply.github.com> Date: Mon, 3 Feb 2025 21:47:38 +0000 Subject: [PATCH] fix client side env variable refresh (#695) --- .../src/integrations/static/static.module.ts | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/apps/server/src/integrations/static/static.module.ts b/apps/server/src/integrations/static/static.module.ts index 13dce2474..e7992aef5 100644 --- a/apps/server/src/integrations/static/static.module.ts +++ b/apps/server/src/integrations/static/static.module.ts @@ -4,6 +4,7 @@ import { join } from 'path'; import * as fs from 'node:fs'; import fastifyStatic from '@fastify/static'; import { EnvironmentService } from '../environment/environment.service'; +import { fileExistsSync } from 'tsconfig-paths/lib/filesystem'; @Module({}) export class StaticModule implements OnModuleInit { @@ -25,20 +26,28 @@ export class StaticModule implements OnModuleInit { 'client/dist', ); - if (fs.existsSync(clientDistPath)) { - const indexFilePath = join(clientDistPath, 'index.html'); + const indexFilePath = join(clientDistPath, 'index.html'); + + if (fs.existsSync(clientDistPath) && fileExistsSync(indexFilePath)) { + const indexTemplateFilePath = join(clientDistPath, 'index-template.html'); const windowVar = ''; const configString = { ENV: this.environmentService.getNodeEnv(), APP_URL: this.environmentService.getAppUrl(), - IS_CLOUD: this.environmentService.isCloud(), - FILE_UPLOAD_SIZE_LIMIT: this.environmentService.getFileUploadSizeLimit(), - DRAWIO_URL: this.environmentService.getDrawioUrl() + CLOUD: this.environmentService.isCloud(), + FILE_UPLOAD_SIZE_LIMIT: + this.environmentService.getFileUploadSizeLimit(), + DRAWIO_URL: this.environmentService.getDrawioUrl(), }; const windowScriptContent = ``; - const html = fs.readFileSync(indexFilePath, 'utf8'); + + if (!fs.existsSync(indexTemplateFilePath)) { + fs.copyFileSync(indexFilePath, indexTemplateFilePath); + } + + const html = fs.readFileSync(indexTemplateFilePath, 'utf8'); const transformedHtml = html.replace(windowVar, windowScriptContent); fs.writeFileSync(indexFilePath, transformedHtml);