Skip to content

Commit 5e50031

Browse files
deewhyweboisinisapotatoe
authored andcommitted
chore(example): Replaced body parser with express JSON parser (#334)
Signed-off-by: Philip Hayes <phayes@redhat.com> Co-authored-by: Philip Hayes <phayes@redhat.com>
1 parent 914181f commit 5e50031

File tree

2 files changed

+3
-14
lines changed

2 files changed

+3
-14
lines changed

examples/express-ex/index.js

+2-14
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,8 @@
33
const express = require("express");
44
const { Receiver } = require("cloudevents");
55
const app = express();
6-
7-
app.use((req, res, next) => {
8-
let data = "";
9-
10-
req.setEncoding("utf8");
11-
req.on("data", function (chunk) {
12-
data += chunk;
13-
});
14-
15-
req.on("end", function () {
16-
req.body = data;
17-
next();
18-
});
19-
});
6+
const bodyParser = require('body-parser')
7+
app.use(bodyParser.json())
208

219
app.post("/", (req, res) => {
2210
console.log("HEADERS", req.headers);

examples/express-ex/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"author": "fabiojose@gmail.com",
1515
"license": "Apache-2.0",
1616
"dependencies": {
17+
"body-parser": "^1.19.0",
1718
"cloudevents": "^3.1.0",
1819
"express": "^4.17.1"
1920
}

0 commit comments

Comments
 (0)