Skip to content

Instantly share code, notes, and snippets.

@noway
Created December 16, 2022 10:28
Show Gist options
  • Save noway/87e2fba1fc4dd3d026a482126f770d92 to your computer and use it in GitHub Desktop.
Save noway/87e2fba1fc4dd3d026a482126f770d92 to your computer and use it in GitHub Desktop.
A script to reproduce body-parser bug in bun that's affecting express.js.
#!/bin/bash
mkdir bun-express-body-parser-bug
cd bun-express-body-parser-bug
cat <<EOT > package.json
{
"name": "bun-express-body-parser-bug",
"module": "index.ts",
"type": "module",
"devDependencies": {
"bun-types": "^0.3.0"
},
"dependencies": {
"@types/express": "^4.17.15",
"express": "^4.18.2"
}
}
EOT
cat <<EOT > index.ts
import express from "express";
const port = 3000;
const app = express();
app.use(express.text());
app.post("/", async (req, res) => {
res.send('ok')
});
app.listen(port, () => {
console.log("Example app listening on port " + port);
fetch("http://localhost:3000", {
method: "POST",
headers: {
"Content-Type": "text/plain",
},
body: "Hello World",
}).then(res => res.text()).then(console.log);
});
EOT
bun install
bun run index.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment