Skip to content

Serving CloudEvent Sample for nodejs is broken #3247

@csantanapr

Description

@csantanapr

Expected Behavior

Working sample cloudevent for nodejs here https://knative.dev/docs/serving/samples/cloudevents/cloudevents-nodejs/

Actual Behavior

Doing the first scenario to run without K_SINK defined it should reply with a new CloudEvent

Steps to Reproduce the Problem

git clone https://github.com/knative/docs.git knative-docs
cd knative-docs/docs/serving/samples/cloudevents/cloudevents-nodejs
docker build --no-cache -t csantanapr/helloworld-nodejs .
docker run --rm -p 8080:8080 csantanapr/helloworld-nodejs

Send a cloudevent

curl -X POST \
    -H "content-type: application/json"  \
    -H "ce-specversion: 1.0"  \
    -H "ce-source: curl-command"  \
    -H "ce-type: curl.demo"  \
    -H "ce-id: 123-abc"  \
    -d '{"name":"Dave"}' \
http://localhost:8080

Logs from the container

Cookie monster is hungry for some cloudevents on port 8080!
Cookie monster is going to reply back with cloudevents
Accepted event: {
  "id": "123-abc",
  "time": "2021-02-13T03:19:57.513Z",
  "type": "curl.demo",
  "source": "curl-command",
  "specversion": "1.0",
  "datacontenttype": "application/json",
  "data": {
    "name": "Dave"
  }
}
ValidationError [TypeError]: invalid payload
  {"keyword":"type","dataPath":".time","schemaPath":"#/definitions/time/type","params":{"type":"string"},"message":"should be string"}
    at Object.validateCloudEvent (/opt/app-root/src/node_modules/cloudevents/dist/event/spec.js:23:19)
    at CloudEvent.validate (/opt/app-root/src/node_modules/cloudevents/dist/event/cloudevent.js:134:27)
    at new CloudEvent (/opt/app-root/src/node_modules/cloudevents/dist/event/cloudevent.js:100:23)
    at receiveAndReply (/opt/app-root/src/index.js:66:25)
    at /opt/app-root/src/index.js:95:43
    at Layer.handle [as handle_request] (/opt/app-root/src/node_modules/express/lib/router/layer.js:95:5)
    at next (/opt/app-root/src/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/opt/app-root/src/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/opt/app-root/src/node_modules/express/lib/router/layer.js:95:5)
    at /opt/app-root/src/node_modules/express/lib/router/index.js:281:22 {
  errors: [
    {
      keyword: 'type',
      dataPath: '.time',
      schemaPath: '#/definitions/time/type',
      params: [Object],
      message: 'should be string'
    }
  ]
}

Metadata

Metadata

Assignees

Labels

kind/bugCategorizes issue or PR as related to a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions