https://github.com/datashaman/datashaman-webhooks
Github webhooks done the easy way.
https://github.com/datashaman/datashaman-webhooks
Last synced: 8 months ago
JSON representation
Github webhooks done the easy way.
- Host: GitHub
- URL: https://github.com/datashaman/datashaman-webhooks
- Owner: datashaman
- License: mit
- Created: 2015-04-29T12:35:16.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2019-12-17T04:11:45.000Z (over 6 years ago)
- Last Synced: 2025-09-01T01:43:43.325Z (9 months ago)
- Language: JavaScript
- Homepage:
- Size: 13.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# datashaman-webhooks
Github webhooks done the easy way.
## howto
Install the package into your Express application:
npm install --save datashaman-webhooks
Then do something like the following (or fork this repository and use _app.js_):
require('dotenv').config()
const express = require('express')
const app = express()
const webhooks = require('datashaman-webhooks')
webhooks.boot(app, process.env.GITHUB_SECRET)
app.post('/', webhooks.router((req, res, event) => {
switch (event) {
case 'ping':
res.send('Ping')
break
default:
res.send('Unhandled event: ' + event)
}
}))
app.listen(process.env.PORT || 8080)
`GITHUB_SECRET` should store the secret from the webhook page on GitHub.
You can attach the webhooks router to any route you like, as long it's a post method.
The boot method sets up the body parser for checking the authenticity of the request,
and leaves an object in req.body, which is the JSON request from GitHub as an object.
If the validation fails, a plain HTTP 404 error is returned.