fix client side env variable refresh (#695)
This commit is contained in:
parent
0f74f03264
commit
d775a61c95
1 changed files with 15 additions and 6 deletions
|
|
@ -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');
|
||||
|
||||
if (fs.existsSync(clientDistPath) && fileExistsSync(indexFilePath)) {
|
||||
const indexTemplateFilePath = join(clientDistPath, 'index-template.html');
|
||||
const windowVar = '<!--window-config-->';
|
||||
|
||||
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 = `<script>window.CONFIG=${JSON.stringify(configString)};</script>`;
|
||||
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);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue