simple webhook forwarder with subscribe and auto cleanup.
npm i -g webhook-forwarder
webhook-forwarder [OPTIONS]
git clone git@github.com:vigour-io/webhook-forwarder.git &&\
cd webhook-forwarder &&\
npm i &&\
npm start -- [OPTIONS]
| option | alias | description |
|---|---|---|
| -p | --port | The port used to listen for incoming webhooks and /subscribe requests |
| -s | --strikes | The amount of times a subscriber is allowed to be unresponsive at a hook forward. When no strikes are left, the subscriber is removed, when responsive, strikes are reset. |
| -d | --database.url | Redis database server to connect to for storing subscription info (true defaults to 127.0.0.1:6379) |
| -w | --database.password | Password to your Redis server |
| -l | --database.label | Identifier used to grab a namespace within the database |
| -h | --help | Show help |
Each option can be set using environment variables in all caps and prefixed with WHF_, with __ for dots.
- DEBUG=[str]
- WHF_PORT=[int]
- WHF_STRIKES=[int]
- WHF_DATABASE__URL=[str]
- WHF_DATABASE__PASSWORD=[str]
- WHF_DATABASE__LABEL=[str]
Used to subscribe to a webhook endpoint, meaning all webhooks landing on this endpoint will be forwarded to the subscriber.
| parameter | description | example |
|---|---|---|
| endpoint | All webhooks landing on this endpoint should be forwarded to the subscriber | travis |
| url | The url that the webhooks should be forwarded to | http://forward-to.me/travis URI encoded http%3A%2F%2Fforward-to.me%2Ftravis |
http://my-webhook-forwarder.com/subscribe?endpoint=travis&url=http%3A%2F%2Fforward-to.me%2Ftravis
Easy way to get these query strings URI encoded:
const querystring = require('querystring')
const exampleString = querystring.stringify({
endpoint: 'travis',
url: 'http://forward-to.me/travis'
})
// exampleString is now
// "endpoint=travis&url=http%3A%2F%2Fforward-to.me%2Ftravis"Any POST requests landing on the forwarder will be accepted, and if there is a subscriber for the endpoint the hookshot was fired on, it will be forwarded.
The databse is used to keep a persistant and possibly shared record of subscribers.
options.database.label is used to create a namespace and enable the forwarder to find it's subscribers on load.
A forwarder with label myLabel will find it's subscribers as follows:
redis> SMEMBERS myLabel
1) "myLabel/travis"
2) "myLabel/endpoint2"
redis> SMEMBERS myLabel/travis
1) "http://forward-to.me/travis"
2) "http://also-to.me/travis"
redis> SMEMBERS myLabel/endpoint2
1) "http://forward-to.me/stuff"
2) "http://random.me-too/webhooks"