Reputation: 671
I have created two resources
angular.module('myApp.services', ['ngResource'])
.factory('Banana', function ($resource) {
return $resource('http://localhost:8080/banana/:bananaId');
})
.factory('Mango', function ($resource) {
return $resource('http://localhost:5000/mango/:mangoId');
});
Both REST-resources seem to work correctly. I have tested them with Postman by sending GET-requests to http://localhost:8080/banana/ and http://localhost:5000/mango/ . In both cases the server responsed with status code 200 OK and returned a non-empty JSON array of banana or mango object.
When I access the REST-Interfaces from within Angular controllers: Mango.query() returns correctly an array of Mangos but Banana.query() returns an empty array.
The Banana back-end is written in java with Jersey:
@Path("banana")
public class BananaCollection {
@GET
@Produces({MediaType.APPLICATION_JSON})
public List<Banana> getBananas() {
return BananaBox.getBananas(); // BananaBox handles the connection to the DB etc.
}
I have no access to the code of the Mango back-end.
What could be the difference between those two?
Upvotes: 0
Views: 66
Reputation: 95772
Although both addresses are on localhost
the different port number means the browser counts them as different domains.
Both locations are from a different port than the original html, so the browser security will kick in and unless the response includes suitable Access-Control-Allow-Origin
header the response data will be blocked from reaching the javascript.
Upvotes: 1