Skip to content

Commit

Permalink
Allow passing a proxy parameter for accessing fontello.com from behin…
Browse files Browse the repository at this point in the history
…d a proxy server

See node-fetch/node-fetch#79 (comment)
  • Loading branch information
franktopel committed Feb 14, 2018
1 parent 04a5059 commit 5226e8e
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/Fontello.js
Expand Up @@ -5,14 +5,16 @@ const unzip = require("unzip")
const fetch = require("node-fetch")
const FormData = require("form-data")
const { RawSource } = require("webpack-sources")
const HttpsProxyAgent = require('https-proxy-agent')

const defaults = {
host: "http://fontello.com"
host: "http://fontello.com",
proxy: null
}

/**
* Fontello helper
*
*
* @class Fontello
*/
class Fontello {
Expand All @@ -28,7 +30,7 @@ class Fontello {

/**
* Request session id
*
*
* @returns {Promise<String>} - New session id
*/
session() {
Expand All @@ -41,7 +43,8 @@ class Fontello {
filename: "config.json",
contentType: "application/json"
})
return fetch(host, { method: "POST", body })
const fetchOptions = this.options.proxy ? Object.assign({}, { method: "POST", body }, { agent: new HttpsProxyAgent(this.options.proxy) }) : { method: "POST", body }
return fetch(host, fetchOptions)
.then(response => {
if(!response.ok) {
throw new Error(response.statusText)
Expand All @@ -59,7 +62,7 @@ class Fontello {

/**
* Fetch fonts
*
*
* @returns {Promise} - Resolves to a map of {Buffer}s
*/
fonts() {
Expand Down Expand Up @@ -94,7 +97,7 @@ class Fontello {

/**
* Convert fonts to webpack Source
*
*
* @returns {Promise} - Resolves to a map of {RawSource}s
*/
assets() {
Expand Down

0 comments on commit 5226e8e

Please sign in to comment.