Skip to content

Commit

Permalink
fix: log proper response status codes in dev (#932)
Browse files Browse the repository at this point in the history
During `dev` we log the method/url/statuscode for every req+res. This fix logs the correct details for every request.

Fixes #931
  • Loading branch information
threepointone authored May 9, 2022
1 parent 68ddad5 commit e95e5a0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
9 changes: 9 additions & 0 deletions .changeset/mighty-hats-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"wrangler": patch
---

fix: log proper response status codes in `dev`

During `dev` we log the method/url/statuscode for every req+res. This fix logs the correct details for every request.

Fixes https://github.com/cloudflare/wrangler2/issues/931
13 changes: 4 additions & 9 deletions packages/wrangler/src/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ export function usePreviewServer({
const request = message.pipe(remote.request(headers));
request.on("response", (responseHeaders) => {
const status = responseHeaders[":status"] ?? 500;

// log all requests to terminal
logger.log(new Date().toLocaleTimeString(), method, url, status);

rewriteRemoteHostToLocalHostInHeaders(
responseHeaders,
previewToken.host,
Expand Down Expand Up @@ -349,15 +353,6 @@ async function createProxyServer(
: createHttpServer();

return server
.on("request", function (req, res) {
// log all requests
logger.log(
new Date().toLocaleTimeString(),
req.method,
req.url,
res.statusCode
);
})
.on("upgrade", (req) => {
// log all websocket connections
logger.log(
Expand Down

0 comments on commit e95e5a0

Please sign in to comment.