HTTP Requests from Angular Service Worker not working

458 Views Asked by At

I'm using Angular 10 Service Worker to subscribe to push notifications. I'm calling this function after login:

subscribeToNotifications(): void {

   this.swPush.requestSubscription({
      serverPublicKey: environment.vapidPublicKey
   })
  .then(sub => this.deviceService.subscribeDevice(sub).subscribe())
  .catch(err => console.error('Could not subscribe to notifications', err));
}

The function subscribeDevice() looks like this:

public subscribeDevice(sub): Observable<any> {
  return this.http.post(`${this.API_URL}/devices/webpush/`, sub, this.options);
}

I'm serving with http-server like so:

http-server -p 4200 -c-1 dist/produccion-angular

However, when executing the function, a 504 gateway timeout comes out:

enter image description here

I checked my backend log and the request is not even being done so obviously it's not the server. I don't know what to do. I read the part in the angular documentation about bypassing the service worker and let the browser handle the request but then this happens:

enter image description here

1

There are 1 best solutions below

0
On

Problem is being caused by the adblocker extension I have installed in Chrome.