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?

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

4 Comments

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
Every Request means what ?
Say a resource request goes from the line <img src='/img/a.jpg'> in the webpage html. Angular HttPInterceptor wouldn't be able to grab it
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...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.