繁体   English   中英

使用带有AWS Lambda的AWS API Gateway在请求的资源上不存在“ Access-Control-Allow-Origin”标头

[英]No 'Access-Control-Allow-Origin' header is present on the requested resource using AWS API Gateway with AWS Lambda

我在后端使用AWS API gatewayAWS Lambda 我为端点启用了cors 但是,当我在浏览器上运行端点时,仅收到以下错误

 No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

使用redux thunk ,我的动作文件如下

import Cookies from 'universal-cookie';
import fetch from 'node-fetch';

export function fetchUsers(){

return (dispatch) => {

  const headers={
    "Content-Type":"application/json",
    "Authorization":cookies.get('idToken')
  }

  return fetch(`${url}/accounts`,{method:"GET",headers:headers }).then(response => console.log(response));
}

我还观察到我的OPTIONSGET请求能够在Web浏览器的网络选项中给出200 OK响应。 当前的API大约需要11秒才能给出响应。

有人可以帮我吗?

不知道您已经采取了其他哪些步骤,但要查看是否有以下帮助,则很难进行故障排除:

  1. 如果启用了CORS, 请不要忘记执行“ Deploy API” 我总是忘记了
  2. 如果APIGateway端点配置为在Integration RequestUse Lambda Proxy integration (在撰写本文时为复选框),则尝试在lambda响应中包括这些headers属性(请参见下文)。 如果使用其他类型的集成,则需要在端点的响应/映射设置中手动设置标题。

     { 'Access-Control-Allow-Origin': '*' , //other optional entries here } 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM