|
| 1 | +# Receive webhooks on your laptop |
| 2 | + |
| 3 | +Most webhook providers (GitHub, Stripe, Slack, Linear, Twilio…) need a public HTTPS URL they can `POST` to. A persistent Cloudflare Tunnel route is the cleanest way to receive them on a local dev machine without spinning up a server. |
| 4 | + |
| 5 | +## Receiver |
| 6 | + |
| 7 | +`webhook_server.py` (FastAPI; same idea works in any framework): |
| 8 | + |
| 9 | +```python |
| 10 | +import json |
| 11 | +from fastapi import FastAPI, Request |
| 12 | + |
| 13 | +app = FastAPI() |
| 14 | + |
| 15 | +@app.post("/webhook/github") |
| 16 | +async def github(req: Request): |
| 17 | + payload = await req.json() |
| 18 | + print(json.dumps(payload, indent=2)) |
| 19 | + return {"received": True} |
| 20 | +``` |
| 21 | + |
| 22 | +## Run + expose |
| 23 | + |
| 24 | +```bash |
| 25 | +# 1. Start the receiver locally |
| 26 | +uvicorn webhook_server:app --host 127.0.0.1 --port 4000 & |
| 27 | + |
| 28 | +# 2. Add a tunnel route - permanent URL even after laptop restarts |
| 29 | +bash scripts/add-route.sh hooks.example.com 4000 \ |
| 30 | + --comment "Local webhook receiver" |
| 31 | + |
| 32 | +# 3. Point GitHub / Stripe / Slack at: |
| 33 | +# https://hooks.example.com/webhook/github |
| 34 | +``` |
| 35 | + |
| 36 | +## Smoke test |
| 37 | + |
| 38 | +Hit it from your phone or another machine to confirm it's reachable: |
| 39 | + |
| 40 | +```bash |
| 41 | +curl -sS -X POST https://hooks.example.com/webhook/github \ |
| 42 | + -H 'Content-Type: application/json' \ |
| 43 | + -d '{"event":"ping"}' |
| 44 | +``` |
| 45 | + |
| 46 | +## Two providers, one domain |
| 47 | + |
| 48 | +Use path-based routing so each provider gets a distinct URL but you only run one tunnel: |
| 49 | + |
| 50 | +```bash |
| 51 | +bash scripts/add-route.sh hooks.example.com 4000 --path "/github.*" --comment "GitHub hooks" |
| 52 | +bash scripts/add-route.sh hooks.example.com 4001 --path "/stripe.*" --comment "Stripe hooks" |
| 53 | +``` |
| 54 | + |
| 55 | +## Verify provider signatures |
| 56 | + |
| 57 | +Cloudflare terminates TLS at the edge, so the request body and headers reach your local service unchanged. That means signature verification (HMAC, JWT, etc.) works exactly as documented by the provider — no extra steps. |
0 commit comments