Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to disable all caching to avoid CORS issues #203

Closed
alexkreidler opened this issue Oct 24, 2020 · 3 comments
Closed

Add option to disable all caching to avoid CORS issues #203

alexkreidler opened this issue Oct 24, 2020 · 3 comments

Comments

@alexkreidler
Copy link

I'm getting

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://www.w3.org/ns/hydra/core#title.
(Reason: header ‘if-modified-since’ is not allowed according to header ‘Access-Control-Allow-Headers’ from CORS preflight response).

It would be nice to disable any caching-related headers so I could avoid this issue. I tried passing {"if-modified-since": undefined} as the second argument to Hydra.loadResource, but no luck, this actually led to the issue occurring on more URLs.

@tpluscode
Copy link
Member

tpluscode commented Oct 25, 2020

Actually, you can do that already by hooking to the Hydra.cacheStrategy.requestCacheHeaders function

It has a default value so you might decorate or replace completely:

import { Hydra, HydraResponse } from 'alcaeus/web'

const defaultCacheHeaders = Hydra.cacheStrategy.requestCacheHeaders

Hydra.cacheStrategy.requestCacheHeaders = (previous: HydraResponse) => {
  if (previous.response.effectiveUri.startsWith('https://www.w3.org/ns/hydra/core#')) {
    // no cache for Hydra
    return null
  }

  return defaultCacheHeaders(previous)
}

@tpluscode
Copy link
Member

But I would repeat what I wrote on public-linked-json

You could be better off bundling shared vocabularies inside your application using @zazuko/rdf-vocabularies

Watch out for PR zazuko/rdf-vocabularies#74 which will allow importing the packaged vocabularies statically, synchronously and without requiring a parser

@alexkreidler
Copy link
Author

Ah, my memory of the capability to configure that was mistaken. Thanks for your response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants