简体   繁体   English

在开发工具上发布api端点待处理请求

[英]Post api endpoint pending request on dev tool

Trying to login using the data I've created which are in the db however when I post the user&pass back to call /api/login endpoint the network response for this endpoint is stuck on pending request. 尝试使用我在db中创建的数据登录,但是当我将user&pass回发给调用/ api / login端点时,此端点的网络响应停留在待处理的请求上。 Check the response and it showing the payload data I'm trying to send back to mongo. 检查响应,并显示我正尝试发送回mongo的有效负载数据。

I tried putting $q defer promise in vm.loginuser controller where the call is happening but no avail. 我尝试将$ q延迟承诺放在正在发生调用但没有用的vm.loginuser控制器中。 Even postman can't do a login process its also stuck on pending request. 即使邮递员也无法执行登录过程,它也停留在待处理请求上。

Angular Ctrl: 角度Ctrl:

vm.loginUser = function () {
        $http.post('/api/login', vm.userlogin).success(function(response){
            console.log('redirect to profile');
        }).error(function(error){
            console.log('err');
        });
    };

also if I use .then instead of .success I get an error "then" of undefined and localhost:3000/[object%20Object] 404 (Not Found) 也如果我使用.then代替.success我碰到一个错误“然后”未定义和localhost:3000/[object%20Object] 404 (Not Found)

server.js to call the login endpoint: server.js调用登录端点:

app.post('/api/login', authController.login);

Module: this console.log returns on cmd, if I use the full code the api get stuck on pending request, not sure if the code is wrong or mongoDB is just taking long to return me the username and password. 模块:此console.log在cmd上返回,如果我使用完整的代码,则api停留在待处理的请求上,不确定代码是否错误,或者mongoDB花费很长时间才能返回用户名和密码。

module.exports.login = function (req, res){
   res.send('test'); // is okay 
   User.find(req.body, function(err, results){
    if(err){
        console.log('Fail to login')
    }

    if(results && results.lenght ===1){
        res.json(req.body.username);
    }
 })
}

html: 的HTML:

<input type="text" class="form-control" id="username" 
    placeholder="Username" ng-model="vm.userlogin.username">

<input type="password" class="form-control" id="exampleInputPassword1" 
    placeholder="Password" ng-model="vm.userlogin.password">

<button type="submit" class="btn btn-default" 
    ng-click="vm.loginUser()">Submit</button>

Can you test this for your Angular login call 您可以为Angular登录通话测试一下吗

$http.post('/api/login', vm.userlogin)
.then(function(success) {

    console.log("SUCCESS");
    console.log(success);

}, function(err) {

    console.log("ERROR");
    console.log(err);

})
.finally(function() {

    console.log("FINALLY");

});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM