forked from DSpace/dspace-angular
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.browser.ts
More file actions
73 lines (61 loc) · 2.33 KB
/
main.browser.ts
File metadata and controls
73 lines (61 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import 'zone.js';
import 'reflect-metadata';
import 'core-js/es/reflect';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { BrowserAppModule } from './modules/app/browser-app.module';
import { environment } from './environments/environment';
import { AppConfig } from './config/app-config.interface';
import { extendEnvironmentWithAppConfig } from './config/config.util';
import { enableProdMode } from '@angular/core';
const bootstrap = () => platformBrowserDynamic()
.bootstrapModule(BrowserAppModule, {});
/**
* We use this to determine have been serven SSR HTML or not.
*
* At this point, {@link environment} may not be in sync with the configuration.
* Therefore, we cannot depend on it to determine how to bootstrap the app.
*/
const hasTransferState = document.querySelector('script#dspace-angular-state') !== null;
const main = () => {
if (environment.production) {
enableProdMode();
}
addMatomoStatistics();
if (hasTransferState) {
// Configuration will be taken from transfer state during initialization
return bootstrap();
} else {
// Configuration must be fetched explicitly
return fetch('assets/config.json')
.then((response) => response.json())
.then((appConfig: AppConfig) => {
// extend environment with app config for browser when not prerendered
extendEnvironmentWithAppConfig(environment, appConfig);
return bootstrap();
});
}
};
function addMatomoStatistics() {
(window as any)._paq = (window as any)._paq || [];
void fetch('assets/config.json')
.then((response) => response.json())
.then((config) => {
const matomoConfig = config.matomo;
// Push all configuration commands first
(window as any)._paq.push(['setTrackerUrl', matomoConfig.hostUrl + 'matomo.php']);
(window as any)._paq.push(['setSiteId', matomoConfig.siteId]);
(window as any)._paq.push(['enableLinkTracking']);
const g = document.createElement('script');
g.type = 'text/javascript';
g.async = true;
g.defer = true;
g.src = matomoConfig.hostUrl + 'matomo.js';
document.getElementsByTagName('head')[0].appendChild(g);
});
}
// support async tag or hmr
if (document.readyState === 'complete' && !hasTransferState) {
main();
} else {
document.addEventListener('DOMContentLoaded', main);
}