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:
parent
f8514062d4
commit
6be3b27514
|
@ -1,17 +1,29 @@
|
||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
|
|
||||||
const express = require("express");
|
const express = require("express");
|
||||||
const { Receiver } = require("cloudevents");
|
const { CloudEvent, HTTP } = require("cloudevents");
|
||||||
const app = express();
|
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) => {
|
app.post("/", (req, res) => {
|
||||||
console.log("HEADERS", req.headers);
|
console.log("HEADERS", req.headers);
|
||||||
console.log("BODY", req.body);
|
console.log("BODY", req.body);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const event = Receiver.accept(req.headers, req.body);
|
const event = HTTP.toEvent({ headers: req.headers, body: req.body });
|
||||||
// respond as an event
|
// respond as an event
|
||||||
const responseEventMessage = new CloudEvent({
|
const responseEventMessage = new CloudEvent({
|
||||||
source: '/',
|
source: '/',
|
||||||
|
|
|
@ -14,8 +14,7 @@
|
||||||
"author": "fabiojose@gmail.com",
|
"author": "fabiojose@gmail.com",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"body-parser": "^1.19.0",
|
"cloudevents": "^4.0.0",
|
||||||
"cloudevents": "^3.1.0",
|
|
||||||
"express": "^4.17.1"
|
"express": "^4.17.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue