Skip to content

Instantly share code, notes, and snippets.

@joyrexus
Last active March 18, 2024 11:03
  • Star 12 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save joyrexus/7898e57be3478b4522ec5654c3cb572e to your computer and use it in GitHub Desktop.
local webhook testing

We can test webhook callbacks with a little http server and a localtunnel.

Run server.js to spin up a local http server on port 8080. It just exposes a top-level route and will print the received header and payload of any request. Then create a localtunnel to have a non-local url that proxies all requests to localhost:8080.


First, install dependencies with npm install.

Then start the express server with npm start.

Then setup a localtunnel with lt --subdomain acme --port 8080

Use https://acme.localtunnel.me/ as the callback url for the webhook you want to test.

{
"name": "local-webhook-testing",
"version": "1.0.0",
"description": "spin up an http server to receive webhook callbacks",
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"keywords": [
"webhooks",
"testing"
],
"author": "joyrexus",
"license": "MIT",
"dependencies": {
"body-parser": "^1.18.2",
"express": "^4.16.2"
}
}
var express = require('express')
var bodyParser = require('body-parser');
var app = express()
app.use(bodyParser.json());
app.post('/', function (req, res) {
console.log(JSON.stringify(req.headers));
console.log(req.body)
res.send('OK')
})
app.listen(8080, function () {
console.log('listening on port 8080')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment