Ionic - CORS « Access-Control-Allow-Origin » with $http.get

Hello,
I’ve developped my api with jee (jax-rs 2.0 technologies) and want to consume it in ionic app.
Each time i’m using $http.get(url…) i always get an error about some CORS: > Blocage d’une requête multi-origines (Cross-Origin Request) : la politique « Same Origin » ne permet pas de consulter la ressource distante située sur http://myServerIp:8080/pdv/api/pdv. Raison : l’en-tête CORS « Access-Control-Allow-Origin » est manquant.
I read this tutorial and created a proxie like this in my ionic.project file:
“proxies”: [
{
“path”: “/api”,
“proxyUrl”: “http://myServerIp:8080/pdv/api
}
]

but still the same error.
I even created a constant in app.js like this:
.constant(‘ApiEndpoint’, {
url: ‘http://myServerIp:8080/pdv/api
});

but the error is still there.

Any solution for me ?

If you are running it in a browser, it will give this error as long as you dont allow the origin of the url from which you are calling the app from the server.
If you run it with a device it will work fine

1 Like