launchdarkly / js-client-sdk

LaunchDarkly Client-side SDK for Browser JavaScript
Other
109 stars 62 forks source link

Angular service worker + LaunchDarkly not working together #221

Closed vladyslav-semenets closed 3 years ago

vladyslav-semenets commented 3 years ago

Description

I've got a fairly large Angular 8 project where we've recently added the built in service worker. Now I'd also like to implement feature toggling through LaunchDarkly.

Using their client-side JS SDK, the service worker appears to modify the requests (using fetch I believe), specifically adding cache-control to Access-Control-Request-Headers, but since this header is not present on the response from LaunchDarkly, the browser refuses to accept it, both breaking the integration and resulting in an infinite loop of connection attempts.

How can I configure my ngsw-config.json to leave these external requests alone? Or should this issue be fixed on the LaunchDarkly side (either through the SDK or in the LD project settings)?

Disabling the service worker fixes the issue, so I'm certain that's where it originates.

Original issue on StackOverflow

bwoskow-ld commented 3 years ago

Hi @VladislavSemenets ,

Thanks for reaching out. I confirmed that Cache-Control is not included in the Access-Control-Request-Headers value for responses coming from LaunchDarkly, however, that's because it is on the CORS header safelist by default.

I'm not familiar with the details of Angular development as we don't use it internally, but from googling your problem I came across this question which may provide a sufficient workaround for you in your ngsw-config.json file. Besides that, I recommend that you continue to look for an Angular-specific solution to the problem.

Cheers, Ben