From b1e8f88d53b6665f3c985aa5a2685e282994c430 Mon Sep 17 00:00:00 2001 From: "Eric L. Goldstein" <3359116+mangs@users.noreply.github.com> Date: Sat, 7 Sep 2024 12:00:56 -0400 Subject: [PATCH] Improve request logging in the development server by using `Request` cloning (#102) --- .github/workflows/publishWorkflow.yml | 2 +- .github/workflows/pullRequestWorkflow.yml | 2 +- CHANGELOG.md | 5 +++++ bun.lockb | Bin 167769 -> 167769 bytes package.json | 6 +++--- src/networkUtils.mts | 22 ++++++---------------- 6 files changed, 16 insertions(+), 21 deletions(-) diff --git a/.github/workflows/publishWorkflow.yml b/.github/workflows/publishWorkflow.yml index d7b5341..6902d57 100644 --- a/.github/workflows/publishWorkflow.yml +++ b/.github/workflows/publishWorkflow.yml @@ -15,7 +15,7 @@ jobs: - uses: actions/checkout@v4 - uses: oven-sh/setup-bun@v2 with: - bun-version: "1.1.26" + bun-version: "1.1.27" - uses: mangs/simple-release-notes-action@v3 with: github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/pullRequestWorkflow.yml b/.github/workflows/pullRequestWorkflow.yml index b1bf52e..53ba7c7 100644 --- a/.github/workflows/pullRequestWorkflow.yml +++ b/.github/workflows/pullRequestWorkflow.yml @@ -10,7 +10,7 @@ jobs: - uses: actions/checkout@v4 - uses: oven-sh/setup-bun@v2 with: - bun-version: "1.1.26" + bun-version: "1.1.27" - run: bun install --frozen-lockfile - run: bun run check:environment - run: bun run check:package-version diff --git a/CHANGELOG.md b/CHANGELOG.md index 2032b27..d6df731 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 2.31.2 + +- Improve request logging in the development server by using `Request` cloning +- Upgrade target Bun version from `1.1.26` to `1.1.27` + ## 2.31.1 - Add usage examples for the `optimize-images` CLI command diff --git a/bun.lockb b/bun.lockb index 199f02fe69916902e9ad5ecc43f5f319c7805b4d..5cbd00e69a0d21f7ece840add9558bf6099191e9 100755 GIT binary patch delta 461 zcmV;;0W$vCo(kEX3Xm=!dX9f>s+~`eV0Cr8UrL^#vVfW^c$Ays(SPz*G#6`Qu}*4C zlk{sSli*Ak1NzCylOP%;lVBPMvnWl>C6lxxG_xpk5CQ=+lOY->vtV^)YJb${?o}gJz8-`+JwFjbp)i=yAHB$&`BzFG2Oya>aaMe% zBbEG99Z>-Q009905B>oF0LuUX000000000000cK?6{%*)5Vc*ddlu%Onx=#@V%~LV z6B4i%WQ$eV5%+-!>|8VZ9~t8qfE~rq21|~>kXN-~dueTKVScSC=FcCaUEnl8fv`m6 zc&&O*=o_OHRz9p2?8J-@!k05&m0HW9@#6fL3v@2uh~8i<1~piN*43>QUM zY+MjvXM$RVh1p`VQ~`0~VjKrhonZv|f<)YhwHE=mwHE@yF9A50@e2YUmzPHZCjmH@ z@e2YUx86qr5i*y87y=@f{TBibw;y@}6$6){DFPsu;7kGsm;ZkP4VN%A0t>fueFEkY D1rNcX delta 461 zcmV;;0W$vCo(kEX3Xm=!X~*HJFSRnkAhQS2s{?;ViF>S#uWl-jF+HYrPyhKfu}*4C zlQeNCli*Ak1Nq6xlOP%;lVBPMvnWl>C6jbNG_xpk5CQ=*lOY->vtV^)YJX>n$PR)g zz(Q8}h6sVCX*Qhy>rUi7GJoJTx+Ii@H^Z!CGR^;3P*qB})t>wQp zIF+GrHh=*D009905B>oF0LuUX000000000000a#7$pTaS{16w*av+ImnJ9~HZN1ZA zWAs|b5JFW(A@umO_9YdCZW$&Fj0GkM~h!!nNN zPSxzMufIg)eGO{5aPrjnkfueFEkY D=&Z*D diff --git a/package.json b/package.json index a65665b..1b09f09 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,12 @@ { "name": "@mangs/bun-utils", - "version": "2.31.1", + "version": "2.31.2", "author": "Eric L. Goldstein", "description": "Useful utils for your Bun projects", "engines": { - "bun": "1.1.26" + "bun": "1.1.27" }, - "packageManager": "bun@1.1.26", + "packageManager": "bun@1.1.27", "homepage": "https://github.com/mangs/bun-utils#readme", "repository": { "type": "git", diff --git a/src/networkUtils.mts b/src/networkUtils.mts index e5e01e9..4a54e6b 100644 --- a/src/networkUtils.mts +++ b/src/networkUtils.mts @@ -206,7 +206,7 @@ async function startDevelopmentServer( const serverOptions: Serve = { development: true, async fetch(request: Request, server: Server): Promise { - // const requestClone = request.clone(); + const requestClone = request.clone(); const [[response, responseError], elapsedTime] = await measureElapsedTime(async () => { const { pathname, search } = new URL(request.url); @@ -234,21 +234,11 @@ async function startDevelopmentServer( if (responseError) { throw responseError; } - if ( - ['DELETE', 'PATCH', 'POST', 'PUT'].includes(request.method) && - onLogRequestBody(request, response) && - !request.bodyUsed - ) { - // const isJsonBody = requestClone.headers.get('content-type') === 'application/json'; - // const requestBody = isJsonBody - // ? ((await requestClone.json()) as unknown) - // : await requestClone.text(); - // if (requestBody) { - // console.log(inspect(requestBody, { depth: Infinity })); - // } - - const isJsonBody = request.headers.get('content-type') === 'application/json'; - const requestBody = isJsonBody ? ((await request.json()) as unknown) : await request.text(); + if (request.body && onLogRequestBody(request, response)) { + const isJsonBody = requestClone.headers.get('content-type') === 'application/json'; + const requestBody = isJsonBody + ? ((await requestClone.json()) as unknown) + : await requestClone.text(); if (requestBody) { process.stdout.write( `${inspect(requestBody, { colors: true, depth: Infinity, sorted: true })}\n`,