Created
March 13, 2019 18:43
-
-
Save epaulet/cd9e3492c6d15738c1d109aa02fa5e59 to your computer and use it in GitHub Desktop.
Rainforest QA Webhook Testing
This file contains 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
var express = require('express'); | |
var request = require('request-promise'); | |
var RFA = require('rainforest-auth'); | |
var auth = new RFA('YOUR_KEY_HERE'); | |
var app = express(); | |
app.post('/webhooks/rainforest', function (req, res, next) { | |
if (req.body.callback_type != 'before_run') { | |
return res.send(200); | |
} | |
if (!auth.verify(req.body.digest, req.body.callback_type, req.body.options)) { | |
return res.send(403); | |
} | |
// This response has to be finished / closed before sending the callback POST request | |
res.status(202).end(async () => { | |
// Do some preparation work for the run here | |
// functionDoingSomeWork(); | |
var callback_url = auth.get_run_callback(req.body.run_id, req.body.callback_type); | |
// And then make the POST request | |
await request( | |
{ uri: callback_url, method: 'POST' } | |
); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment