@@ -15,31 +15,7 @@ let installingCert: boolean;
15
15
// If it doesn't, redirect to the certificate itself (the browser will prompt to install)
16
16
// Note that this function is stringified, and run in the browser, not here in node.
17
17
function ensureCertificateIsInstalled ( ) {
18
- const testUrl = window . location . href . replace ( 'http://' , 'https://' ) . replace ( 'check-cert' , 'test-https' ) ;
19
- const downloadUrl = window . location . href . replace ( 'check-cert' , 'download-cert' ) ;
20
- const reportSuccessUrl = window . location . href . replace ( 'check-cert' , 'report-success' ) ;
21
-
22
- fetch ( testUrl )
23
- . then ( ( ) => true )
24
- . catch ( ( ) => false )
25
- . then ( ( certificateIsTrusted ) => {
26
- if ( certificateIsTrusted ) {
27
- // Report success (ignoring errors) then continue.
28
- fetch ( reportSuccessUrl ) . catch ( ( ) => { } ) . then ( ( ) => {
29
- window . location . replace ( targetUrl ) ;
30
- } ) ;
31
- } else {
32
- // Start trying to prompt the user to install the cert
33
- if ( ! installingCert ) {
34
- installingCert = true ;
35
- document . body . className = 'show-content' ;
36
- const iframe = document . createElement ( 'iframe' ) ;
37
- iframe . src = downloadUrl ;
38
- document . body . appendChild ( iframe ) ;
39
- setInterval ( ensureCertificateIsInstalled , 500 ) ;
40
- }
41
- }
42
- } ) ;
18
+
43
19
}
44
20
45
21
export class CertCheckServer {
@@ -91,8 +67,34 @@ export class CertCheckServer {
91
67
let installingCert = false;
92
68
const targetUrl = ${ JSON . stringify ( targetUrl ) } ;
93
69
94
- ${ ensureCertificateIsInstalled . toString ( ) }
95
- ensureCertificateIsInstalled();
70
+ function ensureCertificateIsInstalled() {
71
+ const testUrl = window.location.href.replace('http://', 'https://').replace('check-cert', 'test-https');
72
+ const downloadUrl = window.location.href.replace('check-cert', 'download-cert');
73
+ const reportSuccessUrl = window.location.href.replace('check-cert', 'report-success');
74
+
75
+ fetch(testUrl)
76
+ .then(() => true)
77
+ .catch(() => false)
78
+ .then((certificateIsTrusted) => {
79
+ if (certificateIsTrusted) {
80
+ // Report success (ignoring errors) then continue.
81
+ fetch(reportSuccessUrl).catch(() => {}).then(() => {
82
+ window.location.replace(targetUrl);
83
+ });
84
+ } else {
85
+ // Start trying to prompt the user to install the cert
86
+ if (!installingCert) {
87
+ installingCert = true;
88
+ document.body.className = 'show-content';
89
+ const iframe = document.createElement('iframe');
90
+ iframe.src = downloadUrl;
91
+ document.body.appendChild(iframe);
92
+ setInterval(ensureCertificateIsInstalled, 500);
93
+ }
94
+ }
95
+ });
96
+ }
97
+ ensureCertificateIsInstalled();
96
98
</script>
97
99
<body>
98
100
<h1>
0 commit comments