Files
grafana/public/app/index.ts
Josh Hunt 91d9cac157 FEMT: Call /bootdata and render grafana (#105176)
* rename /mtfe route to /femt to match project name

* set correct navTree JSON property name

* call GetWebAssets in the request handler to prevent stale assets during development

* Call /bootdata and render grafana

* set nonce on script

* write csp header in index handler

* write report-only csp as well

* debug stuff

* more debug logging

* move importing app into a seperate, async-loaded module

* Clean up comments

* make /femt redirect to / in the frontend

* remove console.log

* remove stale commented code

* call __grafana_load_failed if bootstrap fails

* comment for __grafana_boot_data_promise

* remove console.log

* remove blank newline

* codeowners
2025-05-13 09:58:46 +01:00

35 lines
1.3 KiB
TypeScript

// The new index.html fetches window.grafanaBootData asynchronously.
// Since much of Grafana depends on it in includes side effects at import time,
// we delay loading the rest of the app using import() until the boot data is ready.
// Check if we are hosting files on cdn and set webpack public path
if (window.public_cdn_path) {
__webpack_public_path__ = window.public_cdn_path;
}
// This is a path to the public folder without '/build'
window.__grafana_public_path__ =
__webpack_public_path__.substring(0, __webpack_public_path__.lastIndexOf('build/')) || __webpack_public_path__;
if (window.nonce) {
__webpack_nonce__ = window.nonce;
}
// This is an indication to the window.onLoad failure check that the app bundle has loaded.
window.__grafana_app_bundle_loaded = true;
async function bootstrapWindowData() {
// Wait for window.grafanaBootData is ready. The new index.html loads it from
// an API call, but the old one just sets an immediately resolving promise.
await window.__grafana_boot_data_promise;
// Use eager to ensure the app is included in the initial chunk and does not
// require additional network requests to load.
await import(/* webpackMode: "eager" */ './initApp');
}
bootstrapWindowData().catch((error) => {
console.error('Error bootstrapping Grafana', error);
window.__grafana_load_failed();
});