How to make an http request with CORS

hello, I’m doing an API Rest in NodeJS now it runs in localhost: 3000, in an ionic application I make an HTTP request but I get an error

Failed to load http://localhost:3000/: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://localhost:8100’ is therefore not allowed access.

I have read a lot about this and everywhere they say that I must enable the CORS, but I do not understand if this is in my API or in my application, what is the right thing if I want to upload my API to a server on the internet and the app in Play Strote.
Can this affect the security of my API? How is it avoided?

I made a Service and a method, I call this in my HomePage

getFleet() {
return this.http.get(‘http://localhost:3000’,{headers:{‘Content-Type’: ‘application/json’}});
}

1 Like

See: