psychonautwiki / bifrost

The PsychonautWiki API.
MIT License
51 stars 10 forks source link

Accessing with Apollo from localhost #11

Closed dlbnco closed 5 years ago

dlbnco commented 5 years ago

Hello 👋

Is it possible to use the API from localhost?

I just bootstrapped an app which will consume the API via Apollo GraphQL, and I'm getting this:

Access to fetch at 'https://api.psychonautwiki.org/' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header has a value 'https://psychonautwiki.org' that is not equal to the supplied origin. Have the server send the header with a valid value, or, if an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

I tried following the no-cors suggestion and added the following into my Apollo configuration :

fetchOptions: {
  mode: 'no-cors',
}

This will get rid of the errors, but then the server will respond with 500.

19h commented 5 years ago

Hello @dlbnco! I'm looking into this.

19h commented 5 years ago

The respective access-control headers now accept wildcard requests. Let me know if this fixes your issue.

dlbnco commented 5 years ago

@KenanSulayman yes it does! I can now fetch from the API.

I'm still getting this warning, though:

Cross-Origin Read Blocking (CORB) blocked cross-origin response https://api.psychonautwiki.org/ with MIME type text/html. See https://www.chromestatus.com/feature/5629709824032768 for more details.
19h commented 5 years ago

That's only true as long as you're trying to access the API through outside of the expected entrypoints:

dlbnco commented 5 years ago

@KenanSulayman

I realized that the warning just happens once loading Apollo's Dev Tools, so it must be something with the extension. Querying from the app itself won't return any warnings.

Thanks for sorting this out!