8000 fix: cloudevents from 3.2.0 to 4.0.0 (#376) · lholmquist/sdk-javascript@6be3b27 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6be3b27

Browse files
snyk-botlholmquist
andauthored
fix: cloudevents from 3.2.0 to 4.0.0 (cloudevents#376)
* fix: examples/express-ex/package.json to reduce vulnerabilities The following vulnerabilities are fixed with an upgrade: - https://snyk.io/vuln/SNYK-JS-AXIOS-1038255 * fix(examples): remove the body-parser module. * When a structured formatted CloudEvent comes in, the body parser module does know how to parse it since the content type is not application/json, which resulted in an empty request body Signed-off-by: Lucas Holmquist <lholmqui@redhat.com> Co-authored-by: Lucas Holmquist <lholmqui@redhat.com>
1 parent f851406 commit 6be3b27

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

examples/express-ex/index.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
11
/* eslint-disable */
22

33
const express = require("express");
4-
const { Receiver } = require("cloudevents");
4+
const { CloudEvent, HTTP } = require("cloudevents");
55
const app = express();
6-
const bodyParser = require('body-parser')
7-
app.use(bodyParser.json())
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+
});
820

921
app.post("/", (req, res) => {
1022
console.log("HEADERS", req.headers);
1123
console.log("BODY", req.body);
1224

1325
try {
14-
const event = Receiver.accept(req.headers, req.body);
26+
const event = HTTP.toEvent({ headers: req.headers, body: req.body });
1527
// respond as an event
1628
const responseEventMessage = new CloudEvent({
1729
source: '/',

examples/express-ex/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
"author": "fabiojose@gmail.com",
1515
"license": "Apache-2.0",
1616
"dependencies": {
17-
"body-parser": "^1.19.0",
18-
"cloudevents": "^3.1.0",
17+
"cloudevents": "^4.0.0",
1918
"express": "^4.17.1"
2019
}
2120
}

0 commit comments

Comments
 (0)
0