事件未定义nodejs
Event is not defined nodejs
我从 patreon 收到一个 webhook,当我启动测试时,我得到这个错误:
(node:636) UnhandledPromiseRejectionWarning: ReferenceError: event is not defined
这是我的代码
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
app.post('/', async (req, res) => {
let crypto = require('crypto');
let hash = event.headers['X-Patreon-Signature'],
hmac = crypto.createHmac("md5", 'patreon-secret-removed ;)');
hmac.update(event.body);
let crypted = hmac.digest("hex");
if (crypted === hash) {
console.log("That's good hash! " + hash);
} else {
console.log("Bad hash! " + hash + " crypted " + crypted);
}
})
app.listen(8080)
我该如何替换或定义事件?
let hash = event.headers['X-Patreon-Signature'] << 什么是事件?
也许这是一个请求,而不是一个事件。
我从 patreon 收到一个 webhook,当我启动测试时,我得到这个错误:
(node:636) UnhandledPromiseRejectionWarning: ReferenceError: event is not defined
这是我的代码
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
app.post('/', async (req, res) => {
let crypto = require('crypto');
let hash = event.headers['X-Patreon-Signature'],
hmac = crypto.createHmac("md5", 'patreon-secret-removed ;)');
hmac.update(event.body);
let crypted = hmac.digest("hex");
if (crypted === hash) {
console.log("That's good hash! " + hash);
} else {
console.log("Bad hash! " + hash + " crypted " + crypted);
}
})
app.listen(8080)
我该如何替换或定义事件?
let hash = event.headers['X-Patreon-Signature'] << 什么是事件?
也许这是一个请求,而不是一个事件。