我创建了一个函数(getADconfig)以获取从Mongo连接到我的Active Directory的参数,但是我无法使其正常工作。我正在承诺“待处理”。该函数将在很多地方被调用,但是async / await无法正常工作:
const getADconfig = async function (ADName) {
try {
return ADModel.findOne({name: ADName})
} catch(err) {
throw(err);
}
}
router.get('/findUser/', function(req, res, next) {
var sAMAccountName = req.query.samaccountname;
var ad = req.query.ad;
**Heres where i try to call it**
var config = getADconfig(ad);
console.log(config); // <--- "Promise { <pending> }"
var ad = new ActiveDirectory(config);
ad.findUser(sAMAccountName, function(err, user) {
if (err) {
var errorquery = err.errno;
var errorresult = {};
switch (errorquery) {
case 'ETIMEDOUT':
errorresult = {
"status": "error",
"message": "Connection timeout to AD"
}
break;
}
res.status(500).json(errorresult);
return;
}
if (!user)
res.json({
"Message": 'User: ' + sAMAccountName + ' not found.',
"status": 'error'
});
else
res.json({
"Message": 'User: ' + sAMAccountName + ' found.',
"status": 'ok',
"Userinfo": user
});
}
);
});