Change to use promise
Signed-off-by: Fabio José <fabiojose@gmail.com>
This commit is contained in:
parent
335531745f
commit
e1b04bdcdb
|
@ -22,22 +22,22 @@ app.post('/', function (req, res) {
|
||||||
console.log(req.headers);
|
console.log(req.headers);
|
||||||
console.log(req.body);
|
console.log(req.body);
|
||||||
|
|
||||||
try {
|
unmarshaller.unmarshall(req.body, req.headers)
|
||||||
var event = unmarshaller.unmarshall(req.body, req.headers);
|
.then(event => {
|
||||||
|
// pretty print
|
||||||
// pretty print
|
console.log("Accepted event:");
|
||||||
console.log("Accepted event:");
|
console.log(JSON.stringify(event.format(), null, 2));
|
||||||
console.log(JSON.stringify(event.format(), null, 2));
|
|
||||||
|
|
||||||
res.status(201)
|
|
||||||
.send("Event Accepted");
|
|
||||||
}catch(e) {
|
|
||||||
console.error(e);
|
|
||||||
|
|
||||||
|
res.status(201)
|
||||||
|
.send("Event Accepted");
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.error(err);
|
||||||
res.status(400)
|
res.status(400)
|
||||||
.header("Content-Type", "application/json")
|
.header("Content-Type", "application/json")
|
||||||
.send(JSON.stringify(e));
|
.send(JSON.stringify(err));
|
||||||
}
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
app.listen(3000, function () {
|
app.listen(3000, function () {
|
||||||
|
|
|
@ -15,6 +15,6 @@
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"cloudevents-sdk": "cloudevents/sdk-javascript#receive"
|
"cloudevents-sdk": "cloudevents/sdk-javascript#develop"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue