webhook-simple-forwarder
v2.3.0
Published
Simple webhook forwarder script to send webhooks from a hosted url to your local machine without hassle of setting up tunnels, or port forwarding your own machine, uses webhooks to communicate between client and server
Downloads
83
Maintainers
Readme
Simple webhook forwarder script to send webhooks from a hosted url to your local machine without hassle of setting up tunnels, or port forwarding your own machine, uses webhooks to communicate between client and server
Why?
As opposed to using something like ngrok, this lets you use your own domain/server straight out of the box, which also means you can use the same url to test your webhooks locally while developing.
Also integrates directly into your express app and calls your post endpoints based on the webhook url that is hit, so you don't need to make any changes to your existing configuration
Installation
npm i --save-dev webhook-simple-forwarder
Client Setup (Where you want to receive webhooks)
// your existing index.js
const webhook_forwarder = require('webhook-simple-forwarder')
const express = require('express')
const app = express()
app.use(express.urlencoded({ extended: false }))
app.use(express.json())
app.post('/wh/some-webhook', function(req, res) {
console.log("Received Webhook!!")
console.log(req.body)
res.status(200).send("ok")
})
const server = app.listen(process.env.PORT, () => {
// add this code block, your key, etc
if (process.env.NODE_ENV === 'Development')
webhook_forwarder.client(
server,
'forward.exampledomain.com:3000',
process.env.SECRET_KEY, // replace 'SECRET_KEY' with your own
'/base_path', // optional, can be any base path, for example if you want to allow multiple different client to use the same server
true // true to omit base url from final request url.
)
})
Server Setup (Public endpoint for webhooks to come in)
Place this on a server, that can be accessed publicly (e.g. on somedomain.com or via ip), point your webhook to that server, and once you run the client your webhook endpoints will be hit
// index.js
const webhook_forwarder = require('webhook-simple-forwarder')
webhook_forwarder.server(process.env.SECRET_KEY, true, /*optional port, default: 3000 */) // replace 'SECRET_KEY' to match client
Additional Data Returned
req.body._url
- provides original url webhook was sent to
req.body._headers
- provides original headers sent with the webhook
req.body
- original webhook body
What endpoints can I use?
Use the same endpoints that you have already.
If in production you would receive webhooks to exampledomain.com/wh/some-webhook, and the server hosting this library is located at forward.exampledomain.com
, during development you can send your webhooks to forward.exampledomain.com:3000/wh/some-webhook
and they will be forwarded to your '/wh/some-webhook' endpoint.
This library supports unlimited endpoints.
How to setup my server?
Any server with a public ip or domain will do, you could probably even use cloud functions for this. You can have multiple clients connected at the same time.
Contributing & Issues
This package was made to fix a specific problem I had, therefore some features may be missing.
Feel free to open an issue or make a pull request.