在开发工具上发布api端点待处理请求 [英] Post api endpoint pending request on dev tool

查看:36
本文介绍了在开发工具上发布api端点待处理请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用我在数据库中创建的数据进行登录,但是当我将user& pass回传给/api/login终结点时,该终结点的网络响应将停留在待处理的请求上.检查响应,并显示我正尝试发送回mongo的有效负载数据.

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. Check the response and it showing the payload data I'm trying to send back to mongo.

我尝试在发生呼叫但无济于事的vm.loginuser控制器中放入$ q延迟承诺.甚至邮递员也无法执行登录过程,这也卡在了待处理的请求中.

I tried putting $q defer promise in vm.loginuser controller where the call is happening but no avail. Even postman can't do a login process its also stuck on pending request.

角度Ctrl:

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

如果我使用 .then 而不是 .success ,也会收到未定义的错误"then",并且出现 localhost:3000/[object%20Object] 404(未找到)

also if I use .then instead of .success I get an error "then" of undefined and localhost:3000/[object%20Object] 404 (Not Found)

server.js调用登录端点:

server.js to call the login endpoint:

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

模块:此console.log在cmd上返回,如果我使用完整的代码,则api会卡在待处理的请求上,不确定代码是否错误,或者mongoDB花费很长时间才能向我返回用户名和密码.

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.

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:

<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>

推荐答案

可以为您的Angular登录呼叫测试吗

Can you test this for your Angular login call

$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");

});

这篇关于在开发工具上发布api端点待处理请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆