Last active
August 7, 2020 13:08
-
-
Save afreeland/ed4e4591adde87c952432828e45663cd to your computer and use it in GitHub Desktop.
Webhook middleware (Chargify)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const app = express(); | |
function rawBodySaver(req, res, buf, encoding) { | |
if (buf && buf.length) { | |
req.rawBody = buf.toString(encoding || "utf8"); | |
} | |
} | |
// For parsing application/json | |
app.use(express.json()); | |
// For parsing application/x-www-form-urlencoded (which is the Content-Type from Chargify) | |
// We can add a verify function that allows us access to the Buffer, which we | |
// can then expose it out on the request as `rawBody` | |
app.use(express.urlencoded({ verify: rawBodySaver, extended: true })); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment