在AWS API Gateway上进行如下设置:
示例代码:
fetch('https://your-api-gateway-url', {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error))
在代码中,你需要将“https://your-api-gateway-url”替换成你在AWS网关上创建的API Gateway URL,然后在访问时将不再出现“No 'Access-Control-Allow-Origin' header”的提示。