我正在尝试使用加密写入 MD5 哈希令牌的标头,然后将其作为响应返回。由于某种原因,它实际上并未同步运行。我知道 JS 是一种异步语言,这确实是我现在唯一遇到困难的部分。任何帮助,将不胜感激。
这是我到目前为止所拥有的:
const crypto = require('crypto');
const bodyParser = require('body-parser');
const formidable = require('formidable');
const async = require('async')
app.post('/pushurl/auth', (req, res) =>
var data = req.body.form1data1 + '§' + req.body.form1data2
async.waterfall([
function(callback) {
var token = crypto.createHash('md5').update(data).digest("hex");
callback(null, token);
},
function(token, callback) {
res.writeHead(301,
{Location: '/dashboard?token=' + token}
);
callback(null)
},
function(callback) {
res.end();
callback(null)
}
]);
}
});
输出:
Uncaught Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
<node_internals>/internal/errors.js:256
No debugger available, can not send 'variables'
Process exited with code 1
慕哥6287543
相关分类