diff --git a/server/middleware/findFile.js b/server/middleware/findFile.js index d022ce8..fa79be4 100644 --- a/server/middleware/findFile.js +++ b/server/middleware/findFile.js @@ -1,7 +1,4 @@ const path = require("path"); -const fetch = require("isomorphic-fetch"); -const gunzip = require("gunzip-maybe"); -const tar = require("tar-stream"); const addLeadingSlash = require("../utils/addLeadingSlash"); const createPackageURL = require("../utils/createPackageURL"); diff --git a/server/utils/fetchArchive.js b/server/utils/fetchArchive.js index 002197c..ab02bcb 100644 --- a/server/utils/fetchArchive.js +++ b/server/utils/fetchArchive.js @@ -1,13 +1,31 @@ -const fetch = require("isomorphic-fetch"); +const url = require("url"); +const https = require("https"); const gunzip = require("gunzip-maybe"); const tar = require("tar-stream"); -function fetchArchive(packageConfig) { - const tarballURL = packageConfig.dist.tarball; +const agent = new https.Agent({ + keepAlive: true +}); - return fetch(tarballURL).then(res => - res.body.pipe(gunzip()).pipe(tar.extract()) - ); +function fetchArchive(packageConfig) { + return new Promise((resolve, reject) => { + const tarballURL = url.parse(packageConfig.dist.tarball); + const options = { + hostname: tarballURL.hostname, + path: tarballURL.pathname, + agent: agent + }; + + https + .get(options, res => { + if (res.statusCode === 200) { + resolve(res.pipe(gunzip()).pipe(tar.extract())); + } else { + reject(res); + } + }) + .on("error", reject); + }); } module.exports = fetchArchive;