AWS API Gateway endpoint gives CORS error when POST from static site on S3

前端 未结 9 2408
予麋鹿
予麋鹿 2020-12-16 13:45

I have created an API endpoint with Serverless(serverless.com) which I expose through API Gateway. I\'m getting following error though I have enabled CORS from the

9条回答
  •  一个人的身影
    2020-12-16 14:23

    You need to enable CORS for all the methods. Means, you need to add below three headers for all your methods

                "headers": {
                "Access-Control-Allow-Origin": {
                    "type": "string"
                },
                "Access-Control-Allow-Methods": {
                    "type": "string"
                },
                "Access-Control-Allow-Headers": {
                    "type": "string"
                }
            }
    

    It is tedious task to add these headers to all your methods in JSON.

    Created a utility in Java which automatically adds these headers to Swagger JSON. You can run it before importing it to API Gateway and import the output JSON which has CORS enabled in all the methods

    https://github.com/anandlalvb/SwaggerToAPIGateway

    I hope this utility may help anyone looking for this to do it easily.

提交回复
热议问题