How to add headers to doPost() in Google Apps Script

Viewed 1180

I am trying to configure Google Apps Script to call a function myFunction() whenever a client sends an HTTP POST request to the published URL (https://script.google.com/XXXXXXX/exec)

But I get the CORS error when I try it.

Failed to load https://script.google.com/XXXXXXX/exec: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8081' is therefore not allowed access.

Is there any way to add CORS headers to my server doPost() response?

Code.gs
function doPost(e){
  // this is where I feel I should add something like:
  // var options = { headers: {"Access-Control-Allow-Origin": "*"} }
  myFunction(e);
}

function myFunction(e){
  // do stuff
}
0 Answers
Related