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);