Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 请求后环回JS的未处理错误_Node.js_Api_Loopbackjs - Fatal编程技术网

Node.js 请求后环回JS的未处理错误

Node.js 请求后环回JS的未处理错误,node.js,api,loopbackjs,Node.js,Api,Loopbackjs,请帮帮我,我正在尝试在环回js上创建远程方法,当我的函数返回回调时,显示错误“请求POST的未处理错误”,并使我的响应代码返回到500响应代码,但仍然显示我的结果数据 这是我的密码 'use strict'; // Define Variable Depedencies Here var jwt = require('jsonwebtoken') module.exports = function(Account) { Account.login = function(usernam

请帮帮我,我正在尝试在环回js上创建远程方法,当我的函数返回回调时,显示错误“请求POST的未处理错误”,并使我的响应代码返回到500响应代码,但仍然显示我的结果数据

这是我的密码

'use strict';

// Define Variable Depedencies Here
var jwt = require('jsonwebtoken')

module.exports = function(Account) {
    Account.login = function(username, password, cb) {
        var data = {
            username: username,
            password: password
        }
        var token = jwt.sign({exp: Math.floor(Date.now() / 1000) + (60*60), data: data}, 'secret');
        cb(token)
        // console.log(token)
    }
    Account.remoteMethod('login', {
        description: ['Login With Your Credentials'],
        http: {path: '/login', verb: 'post'},
        accepts: [
            {arg: 'username', type: 'string'},
            {arg: 'password', type: 'string'}
        ],
        returns: {arg: 'token', type: 'string'}
    })

};
这是我的错误:

D:\PROJECT\Backend>node .
Web server listening at: http://localhost:3000
Browse your REST API at http://localhost:3000/explorer
Unhandled error for request POST /api/Accounts/login: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MDE4NTM2MTYsImRhdGEiOnsidXNlcm5hbWUi
OiJhZG1pbiIsInBhc3N3b3JkIjoiMTIzNDUifSwiaWF0IjoxNTAxODUwMDE3fQ.os6ijfYyF8losGywdnrVKrHW3-DYZFSwlOVUvHyPIOk
提前感谢

我发现了我的问题:)

我将“err”放在回调上

所以这是正确的代码

'use strict';

// Define Variable Depedencies Here
var jwt = require('jsonwebtoken')

module.exports = function(Account) {
    Account.login = function(username, password, cb) {
        var data = {
            username: username,
            password: password
        }
        var token = jwt.sign({exp: Math.floor(Date.now() / 1000) + (60*60), data: data}, 'secret');
        cb(err, token)
        // console.log(token)
    }
    Account.remoteMethod('login', {
        description: ['Login With Your Credentials'],
        http: {path: '/login', verb: 'post'},
        accepts: [
            {arg: 'username', type: 'string'},
            {arg: 'password', type: 'string'}
        ],
        returns: {arg: 'token', type: 'string'}
    })

};