AWS API Gate通过API启用Cors

时间:2019-01-28 09:17:52

标签: amazon-web-services aws-api-gateway

我正在尝试使用aws https://docs.aws.amazon.com/apigateway/latest/developerguide/enable-cors-for-resource-using-swagger-importer-tool.html给出的示例中的大方语法通过api启用cors

但这只是启用第一个选项...

/users 
options:
  summary: CORS support
  description: |
    Enable CORS by returning correct headers
  consumes:
    - application/json
  produces:
    - application/json
  tags:
    - CORS
  x-amazon-apigateway-integration:
    type: mock
    requestTemplates:
      application/json: |
        {
          "statusCode" : 200
        }
    responses:
      "default":
        statusCode: "200"
        responseParameters:
          method.response.header.Access-Control-Allow-Headers : "'Content-Type,X-Amz-Date,Authorization,X-Api-Key'"
          method.response.header.Access-Control-Allow-Methods : "'*'"
          method.response.header.Access-Control-Allow-Origin : "'*'"
        responseTemplates:
          application/json: |
            {}
  responses:
    200:
      description: Default response for CORS method
      headers:
        Access-Control-Allow-Headers:
          type: "string"
        Access-Control-Allow-Methods:
          type: "string"
        Access-Control-Allow-Origin:
          type: "string"

波纹管不会执行

/users 
options:
  summary: CORS support
  description: |
    Enable CORS by returning correct headers
  consumes:
    - application/json
  produces:
    - application/json
  tags:
    - CORS
  x-amazon-apigateway-integration:
    type: mock
    requestTemplates:
      application/json: |
        {
          "statusCode" : 200
        }
    responses:
      "default":
        statusCode: "200"
        responseParameters:
          method.response.header.Access-Control-Allow-Headers : "'Content-Type,X-Amz-Date,Authorization,X-Api-Key'"
          method.response.header.Access-Control-Allow-Methods : "'*'"
          method.response.header.Access-Control-Allow-Origin : "'*'"
        responseTemplates:
          application/json: |
            {}
  responses:
    200:
      description: Default response for CORS method
      headers:
        Access-Control-Allow-Headers:
          type: "string"
        Access-Control-Allow-Methods:
          type: "string"
        Access-Control-Allow-Origin:
          type: "string"
 /users/{id} 
 options:
  summary: CORS support
  description: |
    Enable CORS by returning correct headers
  consumes:
    - application/json
  produces:
    - application/json
  tags:
    - CORS
  x-amazon-apigateway-integration:
    type: mock
    requestTemplates:
      application/json: |
        {
          "statusCode" : 200
        }
    responses:
      "default":
        statusCode: "200"
        responseParameters:
          method.response.header.Access-Control-Allow-Headers : "'Content-Type,X-Amz-Date,Authorization,X-Api-Key'"
          method.response.header.Access-Control-Allow-Methods : "'*'"
          method.response.header.Access-Control-Allow-Origin : "'*'"
        responseTemplates:
          application/json: |
            {}
  responses:
    200:
      description: Default response for CORS method
      headers:
        Access-Control-Allow-Headers:
          type: "string"
        Access-Control-Allow-Methods:
          type: "string"
        Access-Control-Allow-Origin:
          type: "string"

0 个答案:

没有答案