Created
September 6, 2017 12:38
-
-
Save realityking/dd2a8b9a7419a3790ea0d59eee23eaa2 to your computer and use it in GitHub Desktop.
Simple webhook receiver
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
'use strict'; | |
const hapi = require('hapi'); | |
const server = new hapi.Server(); | |
// Tell our server that it will listen on port 3001 | |
server.connection({ port: 3001 }); | |
// Setup the route for our webhook | |
server.route({ | |
method: 'POST', | |
path: '/webhook', | |
handler: function (request, reply) { | |
const body = request.payload; | |
const response = reply('Everything is A-OK!'); | |
response.header('Content-Type', 'text/plain'); | |
console.log(request.headers); | |
console.log(body); | |
} | |
}); | |
// Start the server | |
server.start(function (err) { | |
if (err) { | |
throw err | |
} | |
console.log('Server started on port 3001') | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment