3

I'm using Workbox using the background sync plugin. Unfortunately the plugin did not run as expected for my application, which relies on a CORS request.

My app first sends an options preflight request to ensure that the request is allowed, and then the real request is sent.

The problem is that when i go offline, the preflight request fails and crashes my app before my actual request has a chance to be saved in IndexDb and replayed later.

How can i solve this?

I am currently configuring my background sync as suggested in the documentation, but with a cross-origin endpoint, like so:

    const bgSyncPlugin = new workbox.backgroundSync.Plugin('myQueueName', {
      maxRetentionTime: 24 * 60 // Retry for max of 24 Hours
    });

    workbox.routing.registerRoute(
      new RegExp("https://my-api.example.com/api/add"),
      workbox.strategies.networkOnly({
        plugins: [bgSyncPlugin]
      }),
      'POST'
    );

taken from here: https://developers.google.com/web/tools/workbox/modules/workbox-background-sync

I wonder if I should be adding the OPTIONS requests to IndexDB as well?

    workbox.routing.registerRoute(
      new RegExp("https://my-api.example.com/api/add"),
      workbox.strategies.networkOnly({
        plugins: [bgSyncPlugin]
      }),
      'OPTIONS'
    );

Any help would be appreciated :)

modulitos
  • 14,737
  • 16
  • 67
  • 110
  • Hi @ricardogunawan! Did you ever find a solution to this issue? I'm experiencing the same problem Also, I made some minor edits to help clarify your question, I hope that's ok. – modulitos Feb 22 '19 at 00:22
  • no use yet. in the end i delete this function from my app. hope some fix in this feature. – ricardo gunawan Feb 24 '19 at 13:39

0 Answers0