Getting raw body for HMAC-SHA256

  • My NodeBB plugin exposes a webhook where I receive requests from another service that I don't have control over. This service sends a POST request that contains a header which is an HMAC-SHA256 hash of the raw BODY, where the key is provided by this service directly in my account.

    Right now in NodeBB v1.13.1, the only way that I found to retrieve this raw BODY is by directly modifying src/webserver.js by adding the following before configureBodyParser(app):

    app.use('/webhook', bodyParser.text({ type: '*/*' }));

    Is there a better way of doing this without modifying NodeBB's source code?

  • I fixed this by using a static:app.preload hook and then doing this in my plugin:

    var bodyParser = require.main.require('body-parser')
    plugin.preload = function (params, callback) {'/webhook', bodyParser.text({ type: '*/*' }))
        var arr =
        // add Layer to the start of array because NodeBB's bodyParser was loaded first

    From what I searched, there isn't much documentation about modifying the internals of express like that, but it works good.

Log in to reply

Suggested Topics

| |