AWS Lambda从源“ localhost:3000”对“ ...”处的XMLHttpRequest的访问已被CORS策略阻止

时间:2020-05-17 00:07:48

标签: aws-api-gateway serverless-framework aws-serverless

我知道这个问题可能会重复,但是现有的问题都没有指向我没有做的事情...

我已经在AWS Lambda上使用无服务器框架部署了API,但是在使用CORS时遇到了麻烦。

我正在使用React前端中的API的{​​{1}}模块进行获取请求:

aws-amplify

并且在调用端点时出现以下错误:

    async function getProfileItem() {
    return API.get('profile', '/getProfileItem', {
        body: {
            emailId: emailId
        }
    });
}

到目前为止,我已经为Access to XMLHttpRequest at 'https://xxxx.execute-api.region.amazonaws.com/prod/getProfileItem' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status. createupdate创建了三个端点,但是只有get个端点不起作用!

以下是我的serverless.yml的相关部分:

get

不发布我的后端代码,因为请求甚至没有到达后端,只是在浏览器中失败。为何在functions: create: handler: create.main events: - http: path: createProfile method: post cors: true authorizer: aws_iam get: handler: get.main events: - http: path: getPofileItem method: get cors: true authorizer: aws_iam update: handler: update.main events: - http: path: profile/flipPhotoFlag method: put cors: true authorizer: aws_iam get工作正常的情况下,仅使用create方法会发生这种情况的任何线索?

0 个答案:

没有答案