mirror of
https://github.com/Unleash/unleash.git
synced 2024-11-01 19:07:38 +01:00
6f15eb9f4c
## About the changes Stringified JSON still needs to be escaped before being placed in an HTML attribute.
28 lines
827 B
TypeScript
28 lines
827 B
TypeScript
import fs from 'fs';
|
|
import { IUnleashConfig } from '../server-impl';
|
|
import { rewriteHTML } from './rewriteHTML';
|
|
import path from 'path';
|
|
import fetch from 'make-fetch-happen';
|
|
|
|
export async function loadIndexHTML(
|
|
config: IUnleashConfig,
|
|
publicFolder: string,
|
|
): Promise<string> {
|
|
const { cdnPrefix, baseUriPath = '' } = config.server;
|
|
const uiFlags = encodeURI(JSON.stringify(config.ui.flags || '{}'));
|
|
|
|
let indexHTML: string;
|
|
if (cdnPrefix) {
|
|
const res = await fetch(`${cdnPrefix}/index.html`);
|
|
indexHTML = await res.text();
|
|
} else {
|
|
indexHTML = fs
|
|
.readFileSync(
|
|
path.join(config.publicFolder || publicFolder, 'index.html'),
|
|
)
|
|
.toString();
|
|
}
|
|
|
|
return rewriteHTML(indexHTML, baseUriPath, cdnPrefix, uiFlags);
|
|
}
|