From fbe172d20ebc1b1436427cdb94f86db4585a6bd0 Mon Sep 17 00:00:00 2001 From: 4gray Date: Sun, 9 Jan 2022 00:38:21 +0100 Subject: [PATCH] refactor: add cors proxy url for pwa app --- src/app/services/pwa.service.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/app/services/pwa.service.ts b/src/app/services/pwa.service.ts index 79109c593..9b30536f9 100644 --- a/src/app/services/pwa.service.ts +++ b/src/app/services/pwa.service.ts @@ -30,6 +30,9 @@ import { DataService } from './data.service'; providedIn: 'root', }) export class PwaService extends DataService { + /** Proxy URL to avoid CORS issues */ + corsProxyUrl = 'https://api.codetabs.com/v1/proxy?quest='; + /** * Creates an instance of PwaService. * @param dbService database service @@ -136,7 +139,9 @@ export class PwaService extends DataService { this.fetchFromUrl(payload); } else if (type === PLAYLIST_UPDATE) { this.http - .get(payload.url, { responseType: 'text' }) + .get(`${this.corsProxyUrl}${payload.url}`, { + responseType: 'text', + }) .subscribe((response: any) => { const refreshedPlaylist = this.convertFileStringToPlaylist(response); @@ -175,7 +180,9 @@ export class PwaService extends DataService { */ fetchFromUrl(payload: Partial): void { this.http - .get(payload.url, { responseType: 'text' }) + .get(`${this.corsProxyUrl}${payload.url}`, { + responseType: 'text', + }) .subscribe((response: any) => { const parsedPlaylist = this.convertFileStringToPlaylist(response);