From ae039a756f787cc1f62e05974c20308a75be0913 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=9D=E3=83=BC=E3=83=AB=20=E3=82=A6=E3=82=A7=E3=83=83?= =?UTF-8?q?=E3=83=96?= Date: Wed, 12 Dec 2018 12:32:05 -0600 Subject: [PATCH] Switched to jsdelivr from rawgit --- app/views/api.js | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/app/views/api.js b/app/views/api.js index 504a53d..fc2a27e 100644 --- a/app/views/api.js +++ b/app/views/api.js @@ -13,7 +13,9 @@ import headerBlockchain from "../components/api/header-blockchain"; import headerSdk from "../components/api/header-sdk"; 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 sdkApi = "https://cdn.jsdelivr.net/gh/lbryio/lbry@master/docs/api.json"; @@ -149,19 +151,13 @@ function createApiSidebar(apiDetails) { function parseApiFile(urlSlug) { let apiFileLink; - // checks below are related to rate limits, both URLs should return the same content - switch(true) { case (urlSlug === "blockchain"): - apiFileLink = process.env.NODE_ENV === "development" ? - "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"; + apiFileLink = blockchainApi; break; case (urlSlug === "sdk"): - apiFileLink = process.env.NODE_ENV === "development" ? - "https://rawgit.com/lbryio/lbry/master/docs/api.json" : - "https://cdn.rawgit.com/lbryio/lbry/master/docs/api.json"; + apiFileLink = sdkApi; break; default: @@ -170,10 +166,18 @@ function parseApiFile(urlSlug) { if (!apiFileLink) return Promise.reject(new Error("Failed to fetch API docs")); - return fetch(apiFileLink).then(() => fetch(apiFileLink, { - cache: "no-cache" // forces a conditional request - })) - .then(res => res.json().then(body => body)); // res.status 304 = cache validated + return fetch(apiFileLink) + .then(res => { + return res.json(); + }) + .then(() => { + return fetch(apiFileLink, { + cache: "no-cache" // forces a conditional request + }); + }) + .then(res => { + return res.json().then(body => body); + }); } function renderArguments(args) {