AWS API Gateway - CORS + POST not working

前端 未结 9 1805
一生所求
一生所求 2020-12-01 10:34

CORS is really driving me crazy and I\'m really out of ideas as of what to try to make it work.

I have created a simple APIG Api with 1 resource cal

9条回答
  •  粉色の甜心
    2020-12-01 11:21

    I had a similar issue, but with lambda proxy integration:

    • CORS activated on AWS API Gateway using the browser

    • lambda-proxy integration activated

    When using the lambda proxy integration, you can return custom headers from inside the code of the lambda:

            var result = {
            statusCode: data.statusCode | 200,
            headers: {
              "Access-Control-Allow-Origin": "*"
            },
            body: JSON.stringify(responseBody)
        };
        callback(null, result);
    

    This way you get the CORS header sent. I think there might be a better way to get it to work with the lambda proxy integration without coupling the CORS inside the code of the lambda, please let me know if you know.

提交回复
热议问题