Created
December 28, 2017 20:10
-
-
Save cuperman/504dd15115001bbf0a349b7e70c416ed to your computer and use it in GitHub Desktop.
Supporting CORS using SAM
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
// cors_handler.js | |
const ALLOW_HEADERS = [ | |
'Content-Type', | |
'X-Amz-Date', | |
'Authorization', | |
'X-Api-Key', | |
'X-Amz-Security-Token' | |
]; | |
const ALLOW_METHODS = [ | |
'GET', | |
'OPTIONS', | |
'POST' | |
]; | |
const ALLOW_ORIGIN = '*'; | |
export.preflight = (event, context, callback) => { | |
callback({ | |
statusCode: 200, | |
headers: { | |
'Access-Control-Allow-Headers': ALLOW_HEADERS.join(','), | |
'Access-Control-Allow-Methods': ALLOW_METHODS.join(','), | |
'Access-Control-Allow-Origin': ALLOW_ORIGIN | |
}, | |
body: '' | |
}); | |
}; | |
// template.yaml | |
// | |
// Preflight: | |
// Type: AWS::Serverless::Function | |
// Properties: | |
// Handler: cors_handler/preflight | |
// Runtime: nodejs6.10 | |
// CodeUri: ./package.zip | |
// Events: | |
// OptionsPeople: | |
// Type: Api | |
// Properties: | |
// Method: OPTIONS | |
// Path: /people | |
// OptionsPerson: | |
// Type: Api | |
// Properties: | |
// Method: OPTIONS | |
// Path: /people/{personId} | |
// OptionsPlaces: | |
// Type: Api | |
// Properties: | |
// Method: OPTIONS | |
// Path: /places | |
// OptionsPlace: | |
// Type: Api | |
// Properties: | |
// Method: OPTIONS | |
// Path: /places/{placeId} | |
// OptionsThings: | |
// Type: Api | |
// Properties: | |
// Method: OPTIONS | |
// Path: /things | |
// OptionsThing: | |
// Type: Api | |
// Properties: | |
// Method: OPTIONS | |
// Path: /things/{thingId} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment