2015-10-16 93 views
-1

我將我的平均堆棧項目部署到amazon ec2實例,我試圖登錄,它返回我404錯誤(不能POST/api /用戶/登錄)。客戶端和服務器端代碼都在同一個項目中。當我從本地運行項目,它工作正常。可能是什麼問題 ?謝謝。在EC2服務器上的post請求404錯誤

編輯:代碼剪斷添加

從控制器

var credentials = { 
      email : $scope.user.email, 
      password : $scope.user.password 
     }; 


     User.login(credentials) 
      .then(function (response) { 

       // Administrator. Redirect to /admin.html page 
       if($cookies.get('userType') == 0) { 
        $location.path('/admin'); 
       } 

       console.log("From controller "+ response); 

      }) 
      .catch(function(error) { 
       console.log(error); 
      }) 

從服務

  $http({ 
       method : 'POST', 
       url : '/api/user/login', 
       data : data 
      }) 
      .success(function (data, status, headers, config) { 
       object = JSON.parse(Util.toObject(data));console.log(object._id); 
       $cookies.put('userType', object['status']); // 0 for admin 
       $cookies.put('email', object.email); // store the email for session. 
       console.log(object['status'] + ' ' + object.email); 
       $('#loginModal').hide(); 
       deffered.resolve(Util.toObject(data)); 
      }) 
      .error(function (data, status, headers, config) { 
       console.log("Error in Login "+ status); 
       deffered.reject(data); 
      }) 

BE路線

app.use('/api/admin', require('./admin')); 

管理文件夾裏,文件index.js

router.post('/login', controller.login); 

controller.login文件

exports.login = function(req, res) { 
console.log(req.body); 
User.find(req.body, function(err, data) { 
    if (err) { 
     console.log(' Error in finding the data .. '); 
    } 
    else { 
     console.log(' Data found in login ' + JSON.stringify(data)); 
     res.status(200).json(data); 
    } 
}); 
}; 
+0

你將不得不提供更多關於這個的更多細節。因爲你得到一個'404',聽起來像你的服務器正在運行,但它沒有找到你的端點。您確定您的應用程序正在託管並正確投放? – birryree

+0

@birryree這是我得到的錯誤。 POST http://ec2-52-88-27-247.us-west-2.compute.amazonaws.com:9000/api/user/login 404(未找到)(匿名函數)錯誤登錄404 控制器。 js:30無法POST/api/user/login –

+0

@birryree我從bitbucket克隆了項目並安裝了正確的軟件包。我錯過任何配置嗎? –

回答

0

發現到底的問題。我在每個API端點的末尾添加了'/',並且它工作正常。