Import the new way of require specifications
Signed-off-by: Fabio José <fabiojose@gmail.com>
This commit is contained in:
parent
e602736c20
commit
10fbc1df7a
|
@ -1,24 +1,24 @@
|
||||||
var express = require("express");
|
var express = require("express");
|
||||||
var app = express();
|
var app = express();
|
||||||
|
|
||||||
const Unmarshaller02 = require("cloudevents-sdk/http/unmarshaller/v02");
|
const v02 = require("cloudevents-sdk/v02");
|
||||||
var unmarshaller = new Unmarshaller02();
|
var unmarshaller = new v02.HTTPUnmarshaller();
|
||||||
|
|
||||||
app.use((req, res, next) => {
|
app.use((req, res, next) => {
|
||||||
var data='';
|
var data="";
|
||||||
|
|
||||||
req.setEncoding('utf8');
|
req.setEncoding("utf8");
|
||||||
req.on('data', function(chunk) {
|
req.on("data", function(chunk) {
|
||||||
data += chunk;
|
data += chunk;
|
||||||
});
|
});
|
||||||
|
|
||||||
req.on('end', function() {
|
req.on("end", function() {
|
||||||
req.body = data;
|
req.body = data;
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
app.post('/', function (req, res) {
|
app.post("/", function (req, res) {
|
||||||
console.log(req.headers);
|
console.log(req.headers);
|
||||||
console.log(req.body);
|
console.log(req.body);
|
||||||
|
|
||||||
|
@ -29,11 +29,11 @@ app.post('/', function (req, res) {
|
||||||
console.log(JSON.stringify(cloudevent.format(), null, 2));
|
console.log(JSON.stringify(cloudevent.format(), null, 2));
|
||||||
|
|
||||||
res.status(201)
|
res.status(201)
|
||||||
.send("Event Accepted");
|
.send("Event Created");
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
res.status(400)
|
res.status(415)
|
||||||
.header("Content-Type", "application/json")
|
.header("Content-Type", "application/json")
|
||||||
.send(JSON.stringify(err));
|
.send(JSON.stringify(err));
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue