Switched to jsdelivr from rawgit

This commit is contained in:
ポール ウェッブ 2018-12-12 12:32:05 -06:00
parent 19d8913465
commit ae039a756f

View file

@ -13,7 +13,9 @@ import headerBlockchain from "../components/api/header-blockchain";
import headerSdk from "../components/api/header-sdk"; import headerSdk from "../components/api/header-sdk";
import redirects from "../data/redirects.json"; import redirects from "../data/redirects.json";
const blockchainApi = "https://cdn.jsdelivr.net/gh/lbryio/lbrycrd@add_api_docs_scripts/contrib/devtools/generated/api_v1.json";
const fetch = require("make-fetch-happen").defaults({ cacheManager: "./cache" }); const fetch = require("make-fetch-happen").defaults({ cacheManager: "./cache" });
const sdkApi = "https://cdn.jsdelivr.net/gh/lbryio/lbry@master/docs/api.json";
@ -149,19 +151,13 @@ function createApiSidebar(apiDetails) {
function parseApiFile(urlSlug) { function parseApiFile(urlSlug) {
let apiFileLink; let apiFileLink;
// checks below are related to rate limits, both URLs should return the same content
switch(true) { switch(true) {
case (urlSlug === "blockchain"): case (urlSlug === "blockchain"):
apiFileLink = process.env.NODE_ENV === "development" ? apiFileLink = blockchainApi;
"https://rawgit.com/lbryio/lbrycrd/add_api_docs_scripts/contrib/devtools/generated/api_v1.json" :
"https://cdn.rawgit.com/lbryio/lbrycrd/add_api_docs_scripts/contrib/devtools/generated/api_v1.json";
break; break;
case (urlSlug === "sdk"): case (urlSlug === "sdk"):
apiFileLink = process.env.NODE_ENV === "development" ? apiFileLink = sdkApi;
"https://rawgit.com/lbryio/lbry/master/docs/api.json" :
"https://cdn.rawgit.com/lbryio/lbry/master/docs/api.json";
break; break;
default: default:
@ -170,10 +166,18 @@ function parseApiFile(urlSlug) {
if (!apiFileLink) return Promise.reject(new Error("Failed to fetch API docs")); if (!apiFileLink) return Promise.reject(new Error("Failed to fetch API docs"));
return fetch(apiFileLink).then(() => fetch(apiFileLink, { return fetch(apiFileLink)
.then(res => {
return res.json();
})
.then(() => {
return fetch(apiFileLink, {
cache: "no-cache" // forces a conditional request cache: "no-cache" // forces a conditional request
})) });
.then(res => res.json().then(body => body)); // res.status 304 = cache validated })
.then(res => {
return res.json().then(body => body);
});
} }
function renderArguments(args) { function renderArguments(args) {