Skip to content

Commit

Permalink
Improve request logging in the development server by using Request
Browse files Browse the repository at this point in the history
…cloning (#102)
  • Loading branch information
mangs authored Sep 7, 2024
1 parent d15a3c4 commit b1e8f88
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publishWorkflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pullRequestWorkflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Binary file modified bun.lockb
Binary file not shown.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": "[email protected].26",
"packageManager": "[email protected].27",
"homepage": "https://github.com/mangs/bun-utils#readme",
"repository": {
"type": "git",
Expand Down
22 changes: 6 additions & 16 deletions src/networkUtils.mts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ async function startDevelopmentServer(
const serverOptions: Serve = {
development: true,
async fetch(request: Request, server: Server): Promise<Response> {
// const requestClone = request.clone();
const requestClone = request.clone();
const [[response, responseError], elapsedTime] = await measureElapsedTime(async () => {
const { pathname, search } = new URL(request.url);

Expand Down Expand Up @@ -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`,
Expand Down

0 comments on commit b1e8f88

Please sign in to comment.