以下调用函数序列是正确的,但Token
仍未定义,res.json({ verification : Token });
返回 undefined 。
module.exports = function (server) {
var { Lib } = require('Lib');
var lib = new Lib;
var Token = null;
var body = '';
return function verification(req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
res.setHeader('Access-Control-Allow-Credentials', true);
req.on('data', function (chunk) {
body = JSON.parse(chunk);
});
req.on('end', function () {
let updateUUId = function (data) {
console.log('updateUUId', data.VSMS);
return lib.GenerateToken();
};
let checkVerification = function (data,callback) {
console.log('checkVerification', data.UID);
return callback(data);
};
let checkUUID = function (data,callback) {
console.log('checkUUID', data);
return callback(data, updateUUId);
};
switch (req.method) {
case 'POST':
Token = checkUUID(body, checkVerification);
body = '';
break;
default:
response = json.stringify({ 'error': 'Not A POST' });
break;
}
});
req.on('error', function (err) {
res.write(JSON.stringify({ 'error': err.message }));
res.end();
});
console.log(Token);
res.json({ verification : Token });
};
};