Created
October 14, 2018 17:01
-
-
Save ShelbyZ/83831ae2cc7e74bfa8c293b3fdd2c6d5 to your computer and use it in GitHub Desktop.
Twilio Function template to support CORS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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