I'm doing an API with aws lambda and API gateway, but when I make a request with fetch it returns nothing and gives me "No 'Access-Control-Allow-Origin' header is present on the requested resource" message
I tried to use curl and other website to do this request and the answer was
{"statusCode":200,"headers":{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"POST"},"body":"oi"}
And that is what I expected, but using fetch in a js code it returns me the error:
"No 'Access-Control-Allow-Origin' header is present on the requested resource"
And Access-Control-Allow-Origin is already in header of response
The lambda code:
callback(null, {
statusCode: 200,
headers: {
"Access-Control-Allow-Origin":"*",
"Access-Control-Allow-Methods":"POST"
},
body: "oi"
})
}
The fetch code:
fetch('URL', {
method: 'POST',
})
.then((oi) => oi.json())
.then((json) => console.log(json))