sub-packs/apps/zealder-wp/src/helpers/functions.js
function fetchData(url, type, conf, cb) {
  let forUrl;
  switch (type) {
    case 'categories':
      forUrl = `${url}/wp/v2/categories`;
      break;
    case 'post':
      // single 'post'
      forUrl = `${url}/wp/v2/posts?per_page=1`;
      break;
    default:
      // 'posts' - 12 allows complete rows when col number 1-4
      forUrl = `${url}/wp/v2/posts?per_page=12&_embed=1&context=embed`;
  }
  axios.get(forUrl, {params: conf})
   .then((response) => {
     if (response && response.data) {
       var data = response.data;
       var promises = [];
       if (Array.isArray(data)) {
         // iterate array data
         data.forEach(function(item) {
           if ('post' === type && item.featured_media) {
             // for single post, if there is a featured_media, get it's url
             promises.push(new Promise(function(resolve) {
               axios.get(`${url}/wp/v2/media/${item.featured_media}`)
                .then((response) => {
                  if (response && response.data) {
                    item.featured_mediaData = response.data;
                  }
                  resolve();
                });
             }));
           }
         });
       }
       // return data
       Promise.all(promises).then(() => cb(null, data, response.headers));
     }
   });
}
function fetchData(url, type, conf, cb) {
  let forUrl;
  switch (type) {
    case 'categories':
      forUrl = `${url}/wp/v2/categories`;
      break;
    case 'post':
      // single 'post'
      forUrl = `${url}/wp/v2/posts?per_page=1`;
      break;
    default:
      // 'posts' - 12 allows complete rows when col number 1-4
      forUrl = `${url}/wp/v2/posts?per_page=12&_embed=1&context=embed`;
  }
  axios.get(forUrl, {params: conf})
   .then((response) => {
     if (response && response.data) {
       var data = response.data;
       var promises = [];
       if (Array.isArray(data)) {
         // iterate array data
         data.forEach(function(item) {
           if ('post' === type && item.featured_media) {
             // for single post, if there is a featured_media, get it's url
             promises.push(new Promise(function(resolve) {
               axios.get(`${url}/wp/v2/media/${item.featured_media}`)
                .then((response) => {
                  if (response && response.data) {
                    item.featured_mediaData = response.data;
                  }
                  resolve();
                });
             }));
           }
         });
       }
       // return data
       Promise.all(promises).then(() => cb(null, data, response.headers));
     }
   });
}
for fetching any wp post data type (works isomorphic)