File tree Expand file tree Collapse file tree 1 file changed +31
-5
lines changed Expand file tree Collapse file tree 1 file changed +31
-5
lines changed Original file line number Diff line number Diff line change 1
- var express = require ( ' express' ) ;
1
+ var express = require ( " express" ) ;
2
2
var app = express ( ) ;
3
3
4
- app . get ( '/' , function ( req , res ) {
4
+ const Unmarshaller02 = require ( "cloudevents-sdk/http/unmarshaller/v02" ) ;
5
+ var unmarshaller = new Unmarshaller02 ( ) ;
6
+
7
+ app . use ( ( req , res , next ) => {
8
+ var data = '' ;
9
+
10
+ req . setEncoding ( 'utf8' ) ;
11
+ req . on ( 'data' , function ( chunk ) {
12
+ data += chunk ;
13
+ } ) ;
14
+
15
+ req . on ( 'end' , function ( ) {
16
+ req . body = data ;
17
+ next ( ) ;
18
+ } ) ;
19
+ } ) ;
20
+
21
+ app . post ( '/' , function ( req , res ) {
5
22
console . log ( req . headers ) ;
6
23
console . log ( req . body ) ;
7
24
8
- // TODO use the Unmarshaller
9
-
10
- res . send ( 'Hello World!' ) ;
25
+ try {
26
+ var event = unmarshaller . unmarshall ( req . body , req . headers ) ;
27
+
28
+ res . status ( 201 )
29
+ . send ( "Event Accepted" ) ;
30
+ } catch ( e ) {
31
+ console . error ( e ) ;
32
+
33
+ res . status ( 400 )
34
+ . header ( "Content-Type" , "application/json" )
35
+ . send ( JSON . stringify ( e ) ) ;
36
+ }
11
37
} ) ;
12
38
13
39
app . listen ( 3000 , function ( ) {
You can’t perform that action at this time.
0 commit comments