fix: cloudevents from 3.2.0 to 4.0.0 (#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>
This commit is contained in:
Snyk bot 2021-01-06 20:46:21 +02:00 committed by GitHub
parent f8514062d4
commit 6be3b27514
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 6 deletions

View File

@ -1,17 +1,29 @@
/* eslint-disable */
const express = require("express");
const { Receiver } = require("cloudevents");
const { CloudEvent, HTTP } = require("cloudevents");
const app = express();
const bodyParser = require('body-parser')
app.use(bodyParser.json())
app.use((req, res, next) => {
let data = "";
req.setEncoding("utf8");
req.on("data", function (chunk) {
data += chunk;
});
req.on("end", function () {
req.body = data;
next();
});
});
app.post("/", (req, res) => {
console.log("HEADERS", req.headers);
console.log("BODY", req.body);
try {
const event = Receiver.accept(req.headers, req.body);
const event = HTTP.toEvent({ headers: req.headers, body: req.body });
// respond as an event
const responseEventMessage = new CloudEvent({
source: '/',

View File

@ -14,8 +14,7 @@
"author": "fabiojose@gmail.com",
"license": "Apache-2.0",
"dependencies": {
"body-parser": "^1.19.0",
"cloudevents": "^3.1.0",
"cloudevents": "^4.0.0",
"express": "^4.17.1"
}
}