A simple webhook module
# install from npm
npm install huke
# run all the tests
npm install
npm testBy subscribing an event with the webhook and providing a url, when the webhook triger the corresponding event, a POST request is sent to the binding url.
import Hook from 'huke'
const hook = new Hook()
hook.subscribe('event1', 'http://localhost/aftertriger')
hook.triger('event1', {a: 1, b: 2})// create empty hook instance
const hook0 = new Hook()
// can pass a object
const hook1 = new Hook({event1: 'http://localhost/aftertriger'})
// or pass a function to return the configure object
const hook2 = new Hook((fullObj) => {
assert.deepEqual(fullObj, {a: 1, b: 2, events: {event1: 'http://localhost/aftertriger'}})
return fullObj.events
}, {a: 1, b: 2, events: {event1: 'http://localhost/aftertriger'}})const hook = new Hook()
hook.subscribe('event1', 'http://localhost/aftertriger')hook.triger('event1', {a: 1, b: 2})// configure the post request options before send the request
hook.use((opt) => {
opt.headers.Cookie = 'a=b&c=d&e=f'
})
hook.use((opt) => {
opt.auth = 'user:passphase'
})