Skip to content

Instantly share code, notes, and snippets.

@ShelbyZ
Created October 14, 2018 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShelbyZ/83831ae2cc7e74bfa8c293b3fdd2c6d5 to your computer and use it in GitHub Desktop.
Save ShelbyZ/83831ae2cc7e74bfa8c293b3fdd2c6d5 to your computer and use it in GitHub Desktop.
Twilio Function template to support CORS
exports.handler = function(context, event, callback) {
const response = new Twilio.Response();
response.appendHeader('Access-Control-Allow-Origin', '*');
response.appendHeader('Access-Control-Allow-Methods', 'GET, OPTIONS, PUT, POST, DELETE');
response.appendHeader('Access-Control-Allow-Headers', 'Content-Type');
// check if the event has any data and if not assume this is the OPTIONS request
if (Object.keys(event).length === 0) {
response.setStatusCode(200);
callback(null, response);
} else {
// call method here to do actual work
method(context, event, callback, response);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment