Skip to content

Instantly share code, notes, and snippets.

@gillisandrew
Last active October 20, 2020 22:46
Show Gist options
  • Select an option

  • Save gillisandrew/7659ca4466627921169cc3ccdb053c27 to your computer and use it in GitHub Desktop.

Select an option

Save gillisandrew/7659ca4466627921169cc3ccdb053c27 to your computer and use it in GitHub Desktop.
Short request integration for AWS API Gateway mock integration. For use on the OPTIONS method to support CORS.
#set($origin = $input.params().get('header').get('Origin'))
{
## TODO: update regex to match your supported API origins
#if($origin.matches("https?:example.com"))
"statusCode": 204
#set($context.responseOverride.header.Access-Control-Allow-Origin = $origin)
#set($context.responseOverride.header.Access-Control-Allow-Methods = "OPTIONS,GET,PUT,POST,DELETE,PATCH,HEAD")
#set($context.responseOverride.header.Access-Control-Allow-Headers = "Authorization,Content-Type,Accept")
#set($context.responseOverride.header.Access-Control-Max-Age = "86400")
#else
"statusCode": 401
#end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment