Skip to content

Commit 6852581

Browse files
committed
CORS: Use Public Proxy
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
1 parent c8b8582 commit 6852581

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

index.html

+16-4
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,23 @@
2525
</noscript>
2626
<script type="text/javascript">
2727
$(document).ready(function(){
28+
/* work-around for https://github.com/readthedocs/readthedocs.org/issues/6152
29+
* via https://www.npmjs.com/package/cors-anywhere */
30+
$.ajaxPrefilter(function(options) {
31+
if (options.crossDomain && jQuery.support.cors) {
32+
options.url = 'https://cors-anywhere.herokuapp.com/' + options.url;
33+
}
34+
});
35+
2836
/* curl https://readthedocs.org/api/v2/project/?slug=warpx | jq '.results[0].id' */
2937
var warpx_rtd_id = 496616;
3038
/* see https://docs.readthedocs.io/en/stable/api/v2.html#project-versions */
3139
$.ajax({
3240
crossDomain: true,
3341
url: "https://readthedocs.org/api/v2/project/" + warpx_rtd_id.toString() + "/active_versions/",
34-
method: 'GET'
35-
}).then(function(data) {
36-
$.each(data.versions, function(index, value) {
42+
//dataType: "jsonp",
43+
success: function(data) {
44+
$.each(data.versions, function(index, value) {
3745
var version_name = value.slug;
3846
if(version_name != "latest") {
3947
$('ul#earlier').append(
@@ -44,7 +52,11 @@
4452
'</a></li>'
4553
);
4654
}
47-
});
55+
});
56+
},
57+
error: function () {
58+
console.error('Error loading the RTD API endpoint');
59+
},
4860
});
4961
});
5062
</script>

0 commit comments

Comments
 (0)