diff --git a/src/app/core/wordpress/wordpress.service.ts b/src/app/core/wordpress/wordpress.service.ts index 52d5e5931..ebdabcc3a 100644 --- a/src/app/core/wordpress/wordpress.service.ts +++ b/src/app/core/wordpress/wordpress.service.ts @@ -1,5 +1,6 @@ import { HttpClient } from '@angular/common/http' import { Inject, Injectable, LOCALE_ID } from '@angular/core' +import { catchError, map } from 'rxjs/operators' import { WordpressPost } from 'src/app/types/wordpress' import { environment } from 'src/environments/environment' @@ -13,12 +14,44 @@ export class WordpressService { ) {} getHomePagePost() { - return this.httpClient.get( - `${ - environment.WORDPRESS_S3 - }/index${this.getWordpressLocalizationCode()}.html`, - { responseType: 'text' } - ) + const primaryUrl = `${ + environment.WORDPRESS_S3 + }/index${this.getWordpressLocalizationCode()}.html` + const fallbackUrl = `${ + environment.WORDPRESS_S3_FALLBACK + }/index${this.getWordpressLocalizationCode()}.html` + + return this.httpClient + .get(primaryUrl, { responseType: 'text' }) + .pipe( + map((html: string) => { + return { + html: html, + url: environment.WORDPRESS_S3, + } + }) + ) + .pipe( + catchError((error) => { + return this.httpClient + .get(fallbackUrl, { responseType: 'text' }) + .pipe( + map((html: string) => { + return { + html: html, + url: environment.WORDPRESS_S3_FALLBACK, + } + }) + ) + }), + // Update resulting HTML to use the correct base URL + map((data: { html: string; url: string }) => { + const find = './assets/' + const regex = new RegExp(find, 'g') + const updatedHtml = data.html.replace(regex, data.url + '/assets/') + return updatedHtml + }) + ) } getWordpressLocalizationCode() { if (this.locale.includes('en')) { diff --git a/src/app/home/pages/home/home.component.ts b/src/app/home/pages/home/home.component.ts index 88f705ac7..3e098cfe1 100644 --- a/src/app/home/pages/home/home.component.ts +++ b/src/app/home/pages/home/home.component.ts @@ -51,6 +51,7 @@ export class HomeComponent implements OnInit { ) .subscribe((html) => { this.wordpressView = this.sanitizer.bypassSecurityTrustHtml(html) + this.wordpressView }) } diff --git a/src/environments/environment.int.ts b/src/environments/environment.int.ts index e623f148d..1e9534c2c 100644 --- a/src/environments/environment.int.ts +++ b/src/environments/environment.int.ts @@ -16,7 +16,8 @@ export const environment = { CAN_DISABLE_TEST_WARNING_BANNER: true, INSTITUTIONAL_AUTOCOMPLETE_DISPLAY_AMOUNT: 20, VERBOSE_SNACKBAR_ERRORS_REPORTS: true, - WORDPRESS_S3: 'https://d3055hwma3riwo.cloudfront.net', + WORDPRESS_S3: 'https://d25yxmpntoa26z.cloudfront.net', + WORDPRESS_S3_FALLBACK: 'https://d1kh89kum7j2ji.cloudfront.net', LANGUAGE_MENU_OPTIONS: { ar: 'العربية', cs: 'Čeština', diff --git a/src/environments/environment.local-with-proxy.ts b/src/environments/environment.local-with-proxy.ts index 00f138f9f..430bdc65f 100644 --- a/src/environments/environment.local-with-proxy.ts +++ b/src/environments/environment.local-with-proxy.ts @@ -17,6 +17,7 @@ export const environment = { INSTITUTIONAL_AUTOCOMPLETE_DISPLAY_AMOUNT: 50, VERBOSE_SNACKBAR_ERRORS_REPORTS: true, WORDPRESS_S3: 'https://d3055hwma3riwo.cloudfront.net', + WORDPRESS_S3_FALLBACK: 'https://d1kh89kum7j2ji.cloudfront.net', LANGUAGE_MENU_OPTIONS: { ar: 'العربية', cs: 'Čeština', diff --git a/src/environments/environment.local.tomcat.ts b/src/environments/environment.local.tomcat.ts index 8492580c7..c50a9c0fe 100644 --- a/src/environments/environment.local.tomcat.ts +++ b/src/environments/environment.local.tomcat.ts @@ -15,6 +15,7 @@ export const environment = { INSTITUTIONAL_AUTOCOMPLETE_DISPLAY_AMOUNT: 20, VERBOSE_SNACKBAR_ERRORS_REPORTS: true, WORDPRESS_S3: 'https://d3055hwma3riwo.cloudfront.net', + WORDPRESS_S3_FALLBACK: 'https://d1kh89kum7j2ji.cloudfront.net', LANGUAGE_MENU_OPTIONS: { ar: 'العربية', cs: 'Čeština', diff --git a/src/environments/environment.local.ts b/src/environments/environment.local.ts index ed2b19f83..c3a423730 100644 --- a/src/environments/environment.local.ts +++ b/src/environments/environment.local.ts @@ -17,6 +17,7 @@ export const environment = { INSTITUTIONAL_AUTOCOMPLETE_DISPLAY_AMOUNT: 50, VERBOSE_SNACKBAR_ERRORS_REPORTS: true, WORDPRESS_S3: 'https://d3055hwma3riwo.cloudfront.net', + WORDPRESS_S3_FALLBACK: 'https://d1kh89kum7j2ji.cloudfront.net', LANGUAGE_MENU_OPTIONS: { ar: 'العربية', cs: 'Čeština', diff --git a/src/environments/environment.production.ts b/src/environments/environment.production.ts index 1b27c099c..ca2235f5e 100644 --- a/src/environments/environment.production.ts +++ b/src/environments/environment.production.ts @@ -15,7 +15,8 @@ export const environment = { HELP_HERO_ID: 'oYFQMrzFHA', INSTITUTIONAL_AUTOCOMPLETE_DISPLAY_AMOUNT: 20, VERBOSE_SNACKBAR_ERRORS_REPORTS: false, - WORDPRESS_S3: 'https://d3055hwma3riwo.cloudfront.net', + WORDPRESS_S3: 'https://d25yxmpntoa26z.cloudfront.net', + WORDPRESS_S3_FALLBACK: 'https://d1kh89kum7j2ji.cloudfront.net', LANGUAGE_MENU_OPTIONS: { ar: 'العربية', cs: 'Čeština', diff --git a/src/environments/environment.qa.ts b/src/environments/environment.qa.ts index 37a1a5abd..1f0622824 100644 --- a/src/environments/environment.qa.ts +++ b/src/environments/environment.qa.ts @@ -17,6 +17,7 @@ export const environment = { INSTITUTIONAL_AUTOCOMPLETE_DISPLAY_AMOUNT: 20, VERBOSE_SNACKBAR_ERRORS_REPORTS: true, WORDPRESS_S3: 'https://d3055hwma3riwo.cloudfront.net', + WORDPRESS_S3_FALLBACK: 'https://d1kh89kum7j2ji.cloudfront.net', LANGUAGE_MENU_OPTIONS: { ar: 'العربية', cs: 'Čeština', diff --git a/src/environments/environment.sandbox.ts b/src/environments/environment.sandbox.ts index 550e773f2..27fe05b8e 100644 --- a/src/environments/environment.sandbox.ts +++ b/src/environments/environment.sandbox.ts @@ -16,7 +16,8 @@ export const environment = { CAN_DISABLE_TEST_WARNING_BANNER: false, INSTITUTIONAL_AUTOCOMPLETE_DISPLAY_AMOUNT: 20, VERBOSE_SNACKBAR_ERRORS_REPORTS: false, - WORDPRESS_S3: 'https://d3055hwma3riwo.cloudfront.net', + WORDPRESS_S3: 'https://d25yxmpntoa26z.cloudfront.net', + WORDPRESS_S3_FALLBACK: 'https://d1kh89kum7j2ji.cloudfront.net', LANGUAGE_MENU_OPTIONS: { ar: 'العربية', cs: 'Čeština',