Created
December 16, 2022 10:28
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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