Last active
September 12, 2022 22:24
-
-
Save msutkowski/06a5d1e4aa0186e782d4b88b0d5e89a4 to your computer and use it in GitHub Desktop.
an itty-router-based request logger.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* mkdir webhook-tester && cd webhook-tester;npm i -g wrangler;wrangler init | |
* hit y 3 times | |
* npm i -D itty-router itty-router-extras @types/itty-router-extras | |
* | |
* copy and paste the below into src/index.ts | |
* | |
* start the dev server, immediately go into local mode; | |
* wrangler dev --local | |
* | |
* in separate terminal, start quick localtunnel via: | |
* npx localtunnel --port 8787 | |
* | |
* give that url to whatever webhook thing you want to test slack/github/etc/etc | |
* | |
*/ | |
import { Router } from "itty-router"; | |
import { json } from "itty-router-extras"; | |
const router = Router(); | |
// Very simple handler to log json payloads | |
router.all("*", async (req) => { | |
let body; | |
try { | |
body = await req.json?.(); | |
} catch (e) { | |
console.log("error parsing body"); | |
} | |
console.log("$$REQ", req.method, body); | |
return json({ status: "ok" }); | |
}); | |
export default { | |
fetch: router.handle, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment