Skip to content

Commit

Permalink
fix: cloudevents from 3.2.0 to 4.0.0 (#376)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

Co-authored-by: Lucas Holmquist <[email protected]>
  • Loading branch information
snyk-bot and lholmquist authored Jan 6, 2021
1 parent f851406 commit 6be3b27
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
20 changes: 16 additions & 4 deletions examples/express-ex/index.js
Original file line number Diff line number Diff line change
@@ -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: '/',
Expand Down
3 changes: 1 addition & 2 deletions examples/express-ex/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
"author": "[email protected]",
"license": "Apache-2.0",
"dependencies": {
"body-parser": "^1.19.0",
"cloudevents": "^3.1.0",
"cloudevents": "^4.0.0",
"express": "^4.17.1"
}
}

0 comments on commit 6be3b27

Please sign in to comment.