All files / src/lib/util load-index-html.ts

81.82% Statements 9/11
33.33% Branches 1/3
100% Functions 1/1
81.82% Lines 9/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 2561x   61x 61x 61x   61x       151x     151x       151x         151x    
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;
 
    let indexHTML: string;
    Iif (cdnPrefix) {
        const res = await fetch(`${cdnPrefix}/index.html`);
        indexHTML = await res.text();
    } else {
        indexHTML = fs
            .readFileSync(path.join(publicFolder, 'index.html'))
            .toString();
    }
 
    return rewriteHTML(indexHTML, baseUriPath, cdnPrefix);
}