I am using AngularJS which uses a Ruby on Rails API for authentication. I am using the $http service in AngularJS to register a user using a POST request to the backend, however, I am confused as the response I am getting is always retued in HTML and it is of the index page, not the actual data from the rails API. I am testing this in my local environment where the AngularJS app is ruing on localhost:9000, and the Rails API is on localhost:3000. The AngularJS is using a proxy which directs requests to port 3000.
I have tested the response of the Rails API by using curl commands:
$ curl -H "Content-Type: application/json" -d '{"user":{"email":"hi@hi.com","password":"12345678"}}' -X POST http://localhost:9000/api/users.json
which retus the response of:
{"success":true,"info":"Registered","data":{"user":{"id":5,"created_at":"2016-04-24T14:13:24.289Z","updated_at":"2016-04-24T14:13:24.298Z","email":"hi@hi.com","authentication_token":"-49zyhbCiddYdjssQx6i"},"auth_token":"-49zyhbCiddYdjssQx6i"}}
Here is the code in the front-end which is in a controller and has a proxy which directs the call to the backend API:
$scope.register = function() {
$http({
url: '/api/users',
method: 'POST',
data: {
user: $scope.user
}
}).then(
// success
function(response) {
console.log(response.data);
console.log(response.auth_token);
tokenHandler.set( response.auth_token );
$location.path('/');
},
// error
function(response) {
$scope.user.errors = response;
});
};
However, the response when I call the register method is always in HTML and of the index file of my front-end.
Am I missing something here?
