3

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
}
Let Me Tink About It
  • 11,866
  • 13
  • 72
  • 169
  • The error message sounds like you set permission incorrectly on your Google Script. It needs to be published as allow access for anyone, even anonymous. – Chase Nov 25 '17 at 04:16
  • Your doPost() is not implemented properly. See https://stackoverflow.com/questions/45163563/dopost-not-working-in-google-app-script/45165643#45165643. – TheAddonDepot Nov 25 '17 at 22:37

0 Answers0