// Helper to return a RunKit compatible express app (runkit.com/tonic/express-endpoint)
var tonicExpress = require("@runkit/tonic/express-endpoint/1.0.0")
// Provide the exports object to the tonicExpress helper
var app = tonicExpress(module.exports)
var request = require('request')
// Middleware that prevents caching of requests
app.use(function (req, res, next) {
res.header('Cache-Control', 'private, no-cache, no-store, must-revalidate');
res.header('Expires', '-1');
res.header('Pragma', 'no-cache');
next()
});
app.get("/", function(req, res){
var request_number = 17
request({
// To see if request is sent go to: https://requestb.in/1coqbqn1?inspect
url: 'http://requestb.in/1coqbqn1',
method: 'POST',
json: {
request_number: request_number,
message: 'hello'
}
}, function(error, response, body) {
error = (error || response.body.error)
if (error){
res.send('Error: ' + JSON.stringify(error))
}else{
res.send('Request Complete')
}
})
// The line below has to be commented out for the above request to be sent
// I don't care about the request callback() firing, I just want the request to be sent
res.send('Done')
})
// Call the express endpoint by going to:
// https://runkit.io/gragland/58056bc6e9d9ed00130c84d5/branches/master