duro / serverless-binary-cors

A Serverless framework plugin to enable proper cors when APIGateway has binary media types configured
MIT License
14 stars 1 forks source link

Different solution #2

Open rehanvdm opened 4 years ago

rehanvdm commented 4 years ago

Hi, so I just thought I mention that there is a ContentHandling param on the Integration of the method, setting this does the job ("ContentHandling": "CONVERT_TO_TEXT",), no need for that wacky hack

It is a variable NOT available through the AWS Console, only CF and cli.

"digitaldiplomaapirestv1featurecorsfixeventsOPTIONSABE7A0A7": {
      "Type": "AWS::ApiGateway::Method",
      "Properties": {
        "HttpMethod": "OPTIONS",
        "ResourceId": {
          "Ref": "digitaldiplomaapirestv1featurecorsfixeventsAB696234"
        },
        "RestApiId": {
          "Ref": "digitaldiplomaapirestv1featurecorsfixBD6C2ED5"
        },
        "AuthorizationType": "NONE",
        "Integration": {
          "ContentHandling": "CONVERT_TO_TEXT",
          "IntegrationResponses": [
            {
              "ResponseParameters": {
                "method.response.header.Access-Control-Allow-Headers": "'*'",
                "method.response.header.Access-Control-Allow-Origin": "'*'",
                "method.response.header.Access-Control-Allow-Credentials": "'true'",
                "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,GET,PUT,POST,DELETE,PATCH,HEAD'"
              },
              "StatusCode": "204"
            }
          ],
          "RequestTemplates": {
            "application/json": "{ \"statusCode\": 204 }"
          },
          "Type": "MOCK"
        },
        "MethodResponses": [
          {
            "ResponseParameters": {
              "method.response.header.Access-Control-Allow-Headers": true,
              "method.response.header.Access-Control-Allow-Methods": true,
              "method.response.header.Access-Control-Allow-Credentials": true,
              "method.response.header.Access-Control-Allow-Origin": true
            },
            "StatusCode": "204"
          }
        ]
      },
      "Metadata": {
        "aws:cdk:path": "digital-diploma-api-v1-feature-cors-fix/digital-diploma-api-rest-v1-feature-cors-fix/Default/events/OPTIONS/Resource"
      }
    },
jamest-pin commented 4 months ago

In 2024 this is now available in the console.