UNPKG

cosmicjs

Version:

The official client module for Cosmic. This module helps you easily add dynamic content to your website or application using the Cosmic headless CMS.

29 lines (25 loc) 623 B
const axios = require('axios') const init = (config) => { // Accept Encoding in Node if (typeof window === 'undefined') { axios.defaults.headers.common['Accept-Encoding'] = 'gzip, deflate' } if (config && config.token) { axios.defaults.headers.common.Authorization = config.token } } const requestHandler = (method, url, data, headers) => { const config = { method, url, data, headers } return axios(config).then((response) => response.data).catch((error) => { throw (error.response ? error.response.data : error.response) }) } module.exports = { init, requestHandler }