0

I have setup service worker in my angular site. I have the ngsw-config.json. Now I'm using it to cache and prefetch somestuff. But I want this service worker to block requests to domains other than mine. Since I crawl documents from internet and put it in my site, it could send resources and ajax requests to those domains. I dont want that to happen.

I know I can achieve this with service worker in plain JS as given here. But I wanna do it the angular way. Can angular service worker help me out here?

Mani Bharathy
  • 117
  • 1
  • 2
  • 13

1 Answers1

0

Use angular httpinterceptor.

It's a very nice feature of Angular where you can manipulate the request and response as per your business requirement....

Please follow the below link for more details on this...

https://angular.io/api/common/http/HttpInterceptor

vijay sahu
  • 765
  • 1
  • 7
  • 29
  • This HttpInterceptor intercepts only the requests created by angular. It wont intercept say a resource request from the page. I'm expecting someting that intercepts every request. Correct me if I'm wrong – Mani Bharathy Sep 23 '19 at 22:14
  • Every Request means what ? – vijay sahu Sep 24 '19 at 02:40
  • Say a resource request goes from the line in the webpage html. Angular HttPInterceptor wouldn't be able to grab it – Mani Bharathy Sep 24 '19 at 03:15
  • It's a default behaviour of browser you can not stop it from html, If the resources getting call from the html directly then there is no way to stop it. But if you have such requirement then you have to add some firewall or may be some rule on your web server (IIS , Apache) etc... – vijay sahu Sep 24 '19 at 03:27