title: How to add headers to doPost() in Google Apps Script
body: <p>I am trying to configure Google Apps Script to call a function <code>myFunction()</code> whenever a client sends an HTTP POST request to the published URL (<a href="https://script.google.com/XXXXXXX/exec" rel="nofollow noreferrer">https://script.google.com/XXXXXXX/exec</a>)</p>
  
  <p>But I get the CORS error when I try it.</p>
  
  <blockquote>
    <p>Failed to load <a href="https://script.google.com/XXXXXXX/exec" rel="nofollow noreferrer">https://script.google.com/XXXXXXX/exec</a>: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '<a href="http://localhost:8081" rel="nofollow noreferrer">http://localhost:8081</a>' is therefore not allowed access.</p>
  </blockquote>
  
  <p>Is there any way to add CORS headers to my server <code>doPost()</code> response?</p>
  
  Code.gs
  
  <pre><code>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
  }
  </code></pre>