cannot post form in angular - express
<p>I have a problem with post request in angularJS to express.
On the client side there is a HTML form definition:</p>

<pre><code>&lt;div ng-controller="LoginCtrl"&gt;
   &lt;form ng-submit="login()"&gt;
    &lt;div&gt;
        &lt;label&gt;Username&lt;/label&gt;
        &lt;input ng-model="username"&gt;

        &lt;label&gt;Password&lt;/label&gt;
        &lt;input ng-model="password" type="password"&gt;
    &lt;/div&gt;
    &lt;button type="submit"&gt;Submit&lt;/button&gt;
   &lt;/form&gt;
&lt;/div&gt;
</code></pre>

<p>and the post method in the Angular controller:</p>

<pre><code>angular.module('app')
  .controller('LoginCtrl', ['$scope', '$state', '$http', function($scope, $state, $http) {

    $scope.login= function(username, password) {
      console.log('Login');
      $http.post('/login', {username:username, password:password}).then(function(response) {
        if(response.data.success) {
          console.log('logged in');
          $state.go('home');
        }
        else {
          console.log('failed to log in');
        }
      });

    };

    $scope.user = {
      username: '',
      password: ''
    };
}]);
</code></pre>

<p>On the server side in routes there is users.js file in which is defined middleware:</p>

<pre><code>var express = require('express');
var router = express.Router();
var passport = require('passport');
var LocalStrategy = require('passport-local').Strategy;

var User = require('../models/user');

// Login
router.get('/login', function(req, res){
    res.render("login");
});


passport.use('local', new LocalStrategy(
  function(username, password, done) {
   User.getUserByUsername(username, function(err, user){
    if(err) throw err;
    if(!user){
        return done(null, false, {message: 'Unknown User'});
    }

    User.comparePassword(password, user.password, function(err, isMatch){
        if(err) throw err;
        if(isMatch){
            return done(null, user);
        } else {
            return done(null, false, {message: 'Invalid password'});
        }
    });
   });
  }));

passport.serializeUser(function(user, done) {
  done(null, user.id);
});

passport.deserializeUser(function(id, done) {
  User.getUserById(id, function(err, user) {
    done(err, user);
  });
});

router.post('/login',
  passport.authenticate('local', {successRedirect:'/', failureRedirect:'/login',failureFlash: true}),
  function(req, res) {
    res.redirect('/');
  });

module.exports = router;
</code></pre>

<p>When I click on the submit button, the error message appears in the console: <code>POST http://localhost:3000/login 404 (Not Found)</code></p>

<p>Does someone know where could be the problem?</p>