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.
27 lines (23 loc) • 499 B
JavaScript
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)
}
module.exports = {
init,
requestHandler
}