Hello,
I have a problem when I want to access API using fetch()
with vue.js.
In the created()
function of my component I make a call to the api in this way:
fetch('https://rss.mydomain.ch/tt-rss/api/', {
method: "POST",
headers: {
"Accept": "application/json",
"Content-Type": "application/json",
},
body: JSON.stringify({
"sid": "API_KEY",
"op": "getHeadlines",
"feed_id": -3,
"order_by": "date_reverse"
})
})
.then(response => response.json())
.then(data => console.log(data))
And I still get a CORS related error:
Access to fetch at ‘https://rss.mydomain.ch/tt-rss/api/’ from origin ‘http://localhost:8080’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. If an opaque response serves your needs, set the request’s mode to ‘no-cors’ to fetch the resource with CORS disabled.
I understand that I need to set up the “Access-Control-Allow-Origin” header, but how do I do it on the tt-rss API?
TT-RSS runs with docker behind an nginx reverse proxy. I followed the installation as explained here.
When I use Insomnia/Postman, no problem appears.
I have already tried several things:
- add
mode: no-cors
in the query - some solutions proposed in the topics of this forum, but the problem still persists.