如何根据前一个中间件的响应 运行 Express POST 的函数

How to Run the Function with Express POST based the response from the Previous Middleware

我对MEAN.io

很陌生

下面编写的函数 (authDN) 并且在 运行ning 上运行良好,如下所示。

当我直接 运行 函数时,我在控制台中得到了正确的响应

authDN('myuserName', 'myPassword', output);

但我想 运行 函数与 router.post 和 运行 函数 (authDN) ,所以每当 POST 调用我想根据 authDN 返回的响应显示响应,我想将 userNTpasswordpostData 函数传递给 authDN 还有

谁能帮我解决这个问题

var express = require('express');
var router = express.Router();
var ldap = require('ldapjs');
var bodyParser = require('body-parser');
var userNT;
var password;


var app = express();
function authDN(dn, password, cb) {
    var client = ldap.createClient({ url: 'ldap://localhost:389' });
    client.bind(dn, password, function (err) {
        client.unbind();
        cb(err === null, err);
    });

}

function output(res, err) {
    if (res) {
        console.log('success');
    } else {
        console.log('failure');
    }
}



app.use(bodyParser.json()); // support json encoded bodies
app.use(bodyParser.urlencoded({ extended: false })); // support encoded bodies

router.post('/login', postData, authDN(userNT, password, output));

function postData(req, res) {
    userNT = req.body.ntid;
    password = req.body.password
};


module.exports = router;
router.post('/login', postData);

function postData(req, res) {
    userNT = req.body.ntid;
    password = req.body.password;
    authDN(userNT, password, output,res);   //send res also
};

function authDN(dn, password, cb,res) {
    var client = ldap.createClient({ url: 'ldap://localhost:389' });
    client.bind(dn, password, function (err) {
        client.unbind();
       cb(err === null, err,res); //pass res to callback
    });

}

function output(fake_res, err, res) {
    if (fake_res) {
       console.log('success');
       res.send('success')   //here
    } else {
       console.log('failure');
       res.send('failure')   //here
    }
}