You need to cover two bases for successful work of CORS (for example, with swaggerdoc / chrome)
For each path you use:
- Have an OPTIONS answer defining which methods you are processing
- Access-Control-Allow-Origin header title will be returned when your actual method is called
Currently, I have found the simplest solution: 1. The presence of the OPTIONS part processed by the GW mock API 2. The header is added to the unmocked GW API responses
So, if you support the path "/ fred" with GET and POST:
"/ fred" {
"options": {
"consumes": [
"application / json"
],
"produces": [
"application / json"
],
"responses": {
"200": {
"description": "Success",
"schema": {
"$ ref": "# / definitions / Empty"
},
"headers": {
"Access-Control-Allow-Origin": {
"type": "string"
},
"Access-Control-Allow-Methods": {
"type": "string"
},
"Access-Control-Allow-Headers": {
"type": "string"
}
}
}
},
"x-amazon-apigateway-integration": {
"responses": {
"default": {
"statusCode": "200",
"responseParameters": {
"method.response.header.Access-Control-Allow-Methods": "'GET, POST, OPTIONS'",
"method.response.header.Access-Control-Allow-Headers": "'Content-Type, X-Amz-Date, Authorization, X-Api-Key, X-Amz-Security-Token'",
"method.response.header.Access-Control-Allow-Origin": "'*'"
}
}
},
"requestTemplates": {
"application / json": "{\" statusCode \ ": 200}"
},
"passthroughBehavior": "when_no_match",
"type": "mock"
}
}
Then in your actual processor you need to make sure that you have the header "Access-Control-Allow-Origin"
"post": {
"responses": {
"200": {
"description": "Success",
"schema": {
"$ ref": "# / definitions / myrecord"
},
"headers": {
"Access-Control-Allow-Origin": {
"type": "string"
}
},
.....
"x-amazon-apigateway-integration": {
"default": {
"statusCode": "200",
"responseParameters": {
"method.response.header.Access-Control-Allow-Origin": "'*'"
},
"responseTemplates": {
"application / json": "......"
}
}
.....
Please note that you also need to return this header to error messages and