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

CORS: Query from github.io Page #6152

Closed
ax3l opened this issue Sep 7, 2019 · 1 comment
Closed

CORS: Query from github.io Page #6152

ax3l opened this issue Sep 7, 2019 · 1 comment

Comments

@ax3l
Copy link

ax3l commented Sep 7, 2019

Details

  • Read the Docs project URL: any
  • Build URL (if applicable):
  • Read the Docs username (if applicable):

Live page: https://ecp-warpx.github.io
Source: https://github.com/ECP-WarpX/ecp-warpx.github.io

Expected Result

I am trying to query the public RTD API endpoint https://docs.readthedocs.io/en/stable/api/v2.html#project-versions from a github.io page with jQuery.

  <script type="text/javascript">
    $(document).ready(function(){
      var project_rtd_id = 123456;
      /* see https://docs.readthedocs.io/en/stable/api/v2.html#project-versions */
      $.ajax({
         /* crossDomain: true, */
         url: "https://readthedocs.org/api/v2/project/" + project_rtd_id.toString() + "/active_versions/",
         /* dataType: "jsonp", */
         success: function(data) {
           $.each(data.versions, function(index, value) {
             var version_name = value.slug;
             /* do something with version_name */
           });
         },
         error: function () {
            console.error('Error loading the RTD API endpoint');
         },
      });
    });
  </script>

Actual Result

I receive browser errors regarding CORS violations as soon as this page is deployed to github.io:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://readthedocs.org/api/v2/project/<myProjectID>/active_versions/. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

I believe this is caused by a missing HTTP header at the endpoint. We can fix this by adding Access-Control-Allow-Origin: * for responses from readthedocs.org/api/v2/. As a side note, support for JSONP would also be really awesome for v3 :)

ax3l added a commit to ECP-WarpX/ecp-warpx.github.io that referenced this issue Sep 8, 2019
Use a public proxy that adds CORS headers to the public RTD API.
Work-around for:
  readthedocs/readthedocs.org#6152

References:
  https://www.npmjs.com/package/cors-anywhere
  https://cors-anywhere.herokuapp.com
@stsewd
Copy link
Member

stsewd commented Sep 18, 2019

I'm closing this in favor of #6154 where we are discussing how to deal with this.

@stsewd stsewd closed this as completed Sep 18, 2019
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