我知道这个问题可能会重复,但是现有的问题都没有指向我没有做的事情...
我已经在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.
,create
和update
创建了三个端点,但是只有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
方法会发生这种情况的任何线索?