Webhooks are awkward to develop against. The sender, whether it is a payment provider, GitHub or a chat platform, needs a public URL to call. Your handler runs on localhost:3000, behind a home router. The usual answer is a tunnelling service, which gives your laptop a public address for a while.
A tunnel gets the request to your machine, and then it is gone. If your handler crashed on it, you have to trigger the event again on the sender's side, which can mean making another test payment or pushing another commit. If two deliveries behaved differently, you compare them by scrolling through logs. And if your laptop was closed when the webhook fired, the delivery simply failed.
webhook-relay is a self-hosted alternative to tunnelling services, built for webhook development. A small server on a public machine receives the webhooks, records every one, and relays them over a websocket to a CLI on your laptop, which calls your local app. Because every request is stored, you can look at it later, replay it after fixing your handler, and diff two deliveries to see what changed.
Stripe/GitHub/… ──POST──► relay-server /h/stripe ══websocket══► relay (CLI) ──► http://localhost:3000
│ stores every request (your app)
└─ inspector UI: list, detail, replay, diff
What it does
Capture first. The endpoint /h/{channel}/{rest...} reads the body up to a limit, strips hop-by-hop headers, and stores the request in SQLite before doing anything else. A delivery is never lost, even when no client is listening. In that case the sender gets 202 Accepted with the request ID, and the request waits in the inspector.
Relay with the real response. Each channel has at most one connected client, and a newer client replaces the older one. The server sends a JSON request frame over the websocket with a random correlation ID, then waits for the matching response frame or the timeout. The response from your local app goes back to the sender, so signature checks and status-code retries behave as they would in production.
Paths are kept. Anything after the channel name is preserved: /h/stripe/v1/events?x=1 arrives at http://localhost:3000/v1/events?x=1.
Failure is visible. If the local target is unreachable, the sender gets a 502 and the error is stored with the request. The client performs the local HTTP calls concurrently, so one slow handler does not block the others.
A connection that stays up. The server pings every 25 seconds to keep proxies from dropping the websocket. The client reconnects with exponential backoff, but it stops on 401 or 403, because a bad token will not fix itself.
Inspector. Server-rendered html/template pages embedded in the binary, with no JavaScript. You get a list per channel and a detail page per request. Replay re-sends a stored request as a new request linked to the original. Diff renders both requests as text (request line, sorted headers, pretty-printed JSON body) and shows a line diff computed with LCS.
JSON API. GET /api/channels/{c}/requests, GET /api/requests/{id} and POST /api/requests/{id}/replay, with a Bearer token.
Storage. The pure-Go modernc.org/sqlite driver, with no cgo, in WAL mode with one connection. Old requests are pruned per channel on insert.
How to use it
Install both binaries with Go:
go install github.com/AbdeldjalilChougui/webhook-relay/cmd/...@latest
The README also lists prebuilt binaries for Linux, macOS and Windows (amd64 and arm64) on the GitHub releases page. Each archive contains relay-server and relay, and checksums.txt has the SHA-256 sums.
On a server with a public URL, build and start the relay server:
go build -o relay-server ./cmd/relay-server
RELAY_TOKEN=change-me ./relay-server -addr :8080 -db relay.db
On your machine, start the client and point it at your local app:
go build -o relay ./cmd/relay
RELAY_TOKEN=change-me ./relay -server https://relay.example.com -channel stripe -to http://localhost:3000
Then set the webhook URL on the sender's side to https://relay.example.com/h/stripe. The inspector is at https://relay.example.com/, behind HTTP Basic auth: any user name, the token as password.
The server has five flags:
| flag | default | meaning |
|---|---|---|
-addr |
:8080 |
listen address (put TLS in front, for example Caddy or nginx) |
-db |
relay.db |
SQLite file |
-keep |
500 |
requests kept per channel |
-max-body |
1048576 |
bytes stored and forwarded per request |
-timeout |
25s |
how long a webhook waits for your local answer |
RELAY_TOKEN protects the websocket, the inspector and the JSON API. The /h/… endpoints are public by design, since the sender has to be able to reach them without your token.
A typical session then goes like this. The provider sends an event and your handler returns a 500. You open the inspector, read the stored headers and body, fix the code, and press Replay. The same request goes through the relay again, and you never have to trigger a new event on the sender's side. If a later delivery behaves differently, Diff shows which headers or JSON fields changed between the two.
Things to know
- One client per channel. There is no fan-out to several developers. A second client on the same channel replaces the first, so give each developer their own channel name.
- A single shared token. There are no per-channel credentials and no user accounts.
-
Bodies are capped. A body over
-max-bodyis truncated when stored and when forwarded. Streaming and very large payloads are not supported. - It is for webhooks, not general tunnelling. Websocket passthrough is not supported.
- Single instance. The server keeps waiting clients in memory. Scaling horizontally would need a shared pub/sub.
- No TLS termination built in. Run it behind a reverse proxy.
- The UI shows the latest 200 requests per channel. There is no pagination beyond that.
-
What was tested.
go test -race ./...includes end-to-end tests that start the relay server and a real client over a websocket in-process, with anhttptestserver acting as the local app. They cover forwarding (method, path, query, headers, body, status, response headers), storing while no client is connected and then replaying, Bearer and Basic auth, the client giving up on a bad token, invalid channel names, the 502 when the target is down, the inspector pages including the diff output and the replay redirect, and a newer client replacing an older one. There are also unit tests for the store (pruning, round trips) and for the diff.
Why I built it
A generic tunnel solves reachability, and reachability is only the first problem in webhook work. The problems that take the time come after it: reproducing a delivery, understanding why two deliveries differ, and not losing an event that arrived while nothing was listening.
All three have the same answer, which is to keep the request. Once every delivery is stored before anything else happens, replay and diff are small features on top of it, and a closed laptop turns from a failed delivery into a pending one.
Hosting it yourself is the second half of the idea. Webhook payloads can contain customer and payment data, and with this tool they stay in a SQLite file on a server you control. The pieces are deliberately few: one server binary, one client binary, one token, and no JavaScript in the inspector.
Sending the local app's real response back to the sender was also important. A relay that always answers 200 hides bugs, because the sender never retries and a signature failure looks like a success.
Get the code
The server, the client, the inspector and the tests are on GitHub: https://github.com/AbdeldjalilChougui/webhook-relay. It is MIT licensed. Issues and pull requests are welcome.
Originally published at abdeldjalilchougui.biz.
Top comments (0)