'Fetching json data from google apps script webapp

is there a way to get data from a google apps script webapp page without running into cors issues? I run into this when I make a get request from my app (currently running on localhost) to my appscript page. I am trying to get a list of folder names and urls. Please if anyone has an answer it will be much appreciated. Been trying to get past this nightmare for days now. See the error message below and my appscript's code

function getData() {
  var folders = DriveApp.getFolders();
  var foldersArray = [];
  while (folders.hasNext()) {
  var folder = folders.next();
  foldersArray.push([folder.getName(),folder.getUrl()])
  Logger.log(foldersArray)
}
var   json = Object.assign(...foldersArray.map(([k, v]) => ({ [k]: v })));
  console.log(json);

  return json;
}


function doGet(e){   
  var content = getData();
 return ContentService
    .createTextOutput(JSON.stringify(content))
    .setMimeType(ContentService.MimeType.JAVASCRIPT);
}

"Access to fetch at 'https://script.google.com/macros/s/AKfycbwU2jEQda0VRtIstNMcfyyGEO-aHgxRqHOdbZWwJIDcVQj7h2cTMyNUrqejuJQKBvHf_w/exec' from origin 'https://docs.google.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled."



Solution 1:[1]

I ran into a similar problem. The only way I found to solve it was to make the call to the script app from the server side, which probably means you'll just have to implement an ajax call from your client and let your server-side code proxy the request.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 fred02138