1

I'm new to angular JS. I've followed an online tutorial and created a simple login form on the frontend, and linked it to the backend. Or at least I've tried. The backend is a nodejs/express server, which has a route for handling the login attempts from the frontend. It will be checking to see if the username and password used on the form are from an existing user account, or not.

The problem is that for some reason, the http POST call from the angular controller, always results in a ERR_CONNECTION_TIMED_OUT response in the browser console.

The thing is, though if I interface with the api endpoint using curl, it works just fine and the server does exactly what it's supposed to do. Just for some reason the angular frontend form cannot connect to the backend. Here's the angular controller code:

app.controller('loginCtrl, function($scope, $location, $http){
  $scope.login = function(){
    var parameter = JSON.stringify({ username: $scope.username, password: $scope.password });
    $http({
      url: 'https://localhost:8443/api/login'
      method: 'POST',
      data: parameter
    }).then(function(response){
      console.log('success: ' + JSON.stringify(response));
    },
    function(response){
      console.log('failed: ' + JSON.stringify(response));
    });
  }
});

The nodejs backend server is serving content over HTTPS. This controller function (login) is being hit, and the POST is being made, but it simply times out. And again, manually interfacing with these api endpoints works as expected when using curl or wget.

Any insight into the issue or what I'm doing wrong?

user1250991
  • 97
  • 2
  • 12
  • You don't need to `stringify` `parameter`. Can you share `curl` command ? – Mukesh Sharma Apr 03 '17 at 03:55
  • Ok. The curl command being used is: `curl -H "Content-Type: application/json" -X POST -d '{"username":"test","password":"password"}' https://localhost:8443/api/login -k` I just realized that as I was doing this, it looks like it could be the inclusion of the -k switch on the curl command. Perhaps my cert/key pair is not set up properly, and the connection is being rejected for some reason. – user1250991 Apr 03 '17 at 04:12
  • Although you would think that the error would be different, not a timeout error, but some other kind of SSL failure error message. – user1250991 Apr 03 '17 at 04:36
  • It should not be the case. In case of SSL error, it won't show connection timeout error. – Mukesh Sharma Apr 03 '17 at 04:42
  • Yes. It could also be CORS related. I'm continuing to research this further. I need to fully understand CORS, and then determine if this issue could be what is going on here. http://stackoverflow.com/questions/35418688/angular-http-status-1-and-cors – user1250991 Apr 03 '17 at 04:45
  • Yeah, but CORS error are very straightforward. On which port, your web server running, I mean angular app. – Mukesh Sharma Apr 03 '17 at 04:47
  • The backend and frontend servers are running on the same machine. The port for the backend (node) is 3001 (http), but 8443 for httpS. The port for the frontend is 55004, which http requests are forwarded to based on the apache configuration for the webserver. Also, I'm looking into if angular has problems with making http post requests from one port (80 or 3001 or whatever) to a second port (8443). – user1250991 Apr 03 '17 at 04:56

0 Answers0