link-lib icon indicating copy to clipboard operation
link-lib copied to clipboard

Easier CORS settings / requestInitGenerator loop

Open joepio opened this issue 4 years ago • 0 comments

I'd like to be able to fetch URLs from a different domain, which means adding some headers to each request.

I've done this in two projects at this moment: openbesluitvorming and link-solid-boilerplate. In both, the code looks like this:

  const store = new RDFStore()
  const storeOptions = {
    report: handle,
    // This part is for setting CORS.
    api: new DataProcessor({
      requestInitGenerator: new RequestInitGenerator({
        credentials: "omit",
        csrfFieldName: "csrf-token",
        mode: "cors",
        xRequestedWith: "XMLHttpRequest"
      }),
      report: handle,
      store,
    })
   };

it works, but it feel unintuitive, and passing a new RDFStore doesn't feel necessary. When I change api to apiOpts, like so:

  apiOpts: {
    requestInitGenerator: new RequestInitGenerator({
      credentials: "omit",
      csrfFieldName: "csrf-token",
      mode: "cors",
      xRequestedWith: "XMLHttpRequest"
    }),
  }

The fetcher is looping, fetching the same thing over and over again.

joepio avatar Jun 14 '21 14:06 joepio