github.com/mweagle/Sparta@v1.15.0/docs_source/content/reference/apigateway/cors.md (about) 1 --- 2 date: 2016-03-09T19:56:50+01:00 3 title: CORS 4 weight: 20 5 --- 6 7 [Cross Origin Resource Sharing](https://en.wikipedia.org/wiki/Cross-origin_resource_sharing) defines a protocol by which resources on different domains may establish whether cross site operations are permissible. 8 9 Sparta makes CORS support a single `CORSEnabled` field of the [API](https://godoc.org/github.com/mweagle/Sparta#API) struct: 10 11 ```go 12 13 // Register the function with the API Gateway 14 apiStage := sparta.NewStage("v1") 15 apiGateway := sparta.NewAPIGateway("SpartaHTML", apiStage) 16 // Enable CORS s.t. the S3 site can access the resources 17 apiGateway.CORSEnabled = true 18 19 ``` 20 21 Setting the boolean to `true` will add the necessary `OPTIONS` and mock responses to _all_ resources exposed by your API. See the [SpartaHTML](/reference/s3site) sample for a complete example. 22 23 # Customization 24 25 Sparta provides two ways to customize the CORS headers available: 26 27 * Via the [apigateway.CORSOptions](https://godoc.org/github.com/mweagle/Sparta#CORSOptions) field. 28 * Customization may use the [S3Site.CloudformationS3ResourceName](https://godoc.org/github.com/mweagle/Sparta#S3Site) to get the _WebsiteURL_ value so that the CORS origin options can be minimally scoped. 29 30 # References 31 32 * [API Gateway Docs](http://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-cors.html)