From 027fbda327949cbb681dfe7e4c818ab20b9dee33 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: Tue, 8 Jan 2019 11:25:34 -0600 Subject: [PATCH] Removed "make-fetch-happen" package --- app/views/api.js | 29 +++++++++++++---------------- package.json | 1 - 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/app/views/api.js b/app/views/api.js index ace444b..41c0e2e 100644 --- a/app/views/api.js +++ b/app/views/api.js @@ -6,6 +6,7 @@ import asyncHtml from "choo-async/html"; import dedent from "dedent"; +import got from "got"; // U T I L S @@ -14,7 +15,7 @@ import headerSdk from "../components/api/header-sdk"; import redirects from "../data/redirects.json"; const blockchainApi = "https://cdn.jsdelivr.net/gh/lbryio/lbrycrd@master/contrib/devtools/generated/api_v1.json"; -const fetch = require("make-fetch-happen").defaults({ cacheManager: "./cache" }); +const cache = new Map(); const sdkApi = "https://cdn.jsdelivr.net/gh/lbryio/lbry@master/docs/api.json"; @@ -57,7 +58,7 @@ export default async(state) => { `; } - catch (error) { + catch(error) { const redirectUrl = redirects[state.href]; return asyncHtml` @@ -148,7 +149,7 @@ function createApiSidebar(apiDetails) { return apiSidebar; } -function parseApiFile(urlSlug) { +async function parseApiFile(urlSlug) { let apiFileLink; switch(true) { @@ -164,20 +165,16 @@ function parseApiFile(urlSlug) { break; } - 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(res => { - return res.json(); - }) - .then(() => { - return fetch(apiFileLink, { - cache: "no-cache" // forces a conditional request - }); - }) - .then(res => { - return res.json().then(body => body); - }); + const response = await got(apiFileLink, { cache: cache, json: true }); + + try { + return response.body; + } catch(error) { + return "Issue loading API documentation"; + } } function renderArguments(args) { diff --git a/package.json b/package.json index 8d4da65..6ddfca7 100755 --- a/package.json +++ b/package.json @@ -30,7 +30,6 @@ "got": "^9.5.0", "graceful-fs": "^4.1.15", "heroku-ssl-redirect": "0.0.4", - "make-fetch-happen": "^4.0.1", "make-promises-safe": "^4.0.0", "markdown-it": "^8.4.2", "markdown-it-anchor": "^5.0.2",