I'm a beginner in JS and webdev spent the last days trying to figure out a CORS issue.
I want to fetch poems from my database that is connected with an API through Cyclic.sh
https://send4t-github-io.vercel.app/poems.html
async function getPoems() {
try {
const response = await fetch('https://extinct-jade-bedclothes.cyclic.app/');
const data = await response.json();
console.log(data);
} catch (error) {
console.error(error);
}
}
getPoems();
getPoems would get me the text 'Yo' from the above URL
However I'm getting CORS error.
I tried different methods getting rid of CORS and trying to work with my API.
My site is deployed on Vercel so I updated vercel.json
{
"routes": [
{
"src": "/(.*)", //I assumed this allows any website to access
"methods": ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS","FETCH"],
"headers": {
"Access-Control-Allow-Origin": "*"
}
}
]
}
Also put CORS requirement into Cyclic's package.json
I recognize the issue might be in Cyclic but their documentation doesn't say anything else. Only says I need to install and require CORS.
What am I missing here?