oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.87k stars 2.74k forks source link

Status Code and Size Response is not logged using Express Framework and Morgan Middleware #10839

Open DevJaGz opened 5 months ago

DevJaGz commented 5 months ago

What version of Bun is running?

1.0.7

What platform is your computer?

Linux 5.15.146.1-microsoft-standard-WSL2 x86_64 x86_64

What steps can reproduce the bug?

  1. Create a bun JavaScript project.
  2. Install the following dependencies using bun add express morgan
  3. Create a file called main.js.
  4. Write the following code snippet in main.js:
    
    import express from "express";
    import morgan from "morgan";

const api = express();

morgan.token("who", (req) => { const who = req.headers["origin"] || req.headers["user-agent"] || "Unknown WHO"; return who; });

api.use( morgan( '[:date[web]] (:who) ":method :url HTTP/:http-version" :status :res[content-length] :response-time ms' ) );

api.get("/", (req, res) => { res.send("Hello World!"); });

api.listen(3000, async () => { console.log( Server started on port 3000 ); });



5. Run `bun run main.js`.
6. Open the `http://localhost:3000/` in the browser.
7. Check the logs.

### What is the expected behavior?

The log must include the status code and size of the response, as it is shown in the following log (the log was obtained after running the code snippet with node - `node main.js`):

[Sat, 04 May 2024 23:31:35 GMT] (Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36) "GET / HTTP/1.1" 200 12 10.813 ms

### What do you see instead?

As it is shown in the following log, the status code and size of the response is missing ("-"):

[Sat, 04 May 2024 23:34:38 GMT] (Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36) "GET / HTTP/1.1" - - 1.703 ms

### Additional information

If you run the code snippet in the file using `node main.js` the logs are correct, the problem happens when is run using `bun run main.js`
nzapponi commented 1 month ago

+1

Blisse1 commented 3 weeks ago

+1