openfaas-incubator / node10-express-template

Node.js 10 Express Template for OpenFaaS
MIT License
24 stars 26 forks source link

event.body is empty when using kafka-connector #12

Closed yvz5 closed 4 years ago

yvz5 commented 4 years ago

I am using kafka-connector to trigger a function but the body is always empty. I set RAW_BODY to true but it is still empty. Is there another way I can try to solve this issues ?

here is the log of the function request:

{
    "body": {},
    "headers": {
      "host": "transform.openfaas-fn.svc.cluster.local:8080",
      "user-agent": "Go-http-client/1.1",
      "transfer-encoding": "chunked",
      "accept-encoding": "gzip",
      "x-forwarded-for": "10.244.0.193:58756",
      "x-forwarded-host": "gateway.openfaas:8080"
    },
    "method": "POST",
    "query": {},
    "path": "/"
  }
}
alexellis commented 4 years ago

Hi the template you should be using is node12, can you switch please?

I don't believe that this template supported the raw body anyway.

Alex

yvz5 commented 4 years ago

Which one is it ? its not under this organization

alexellis commented 4 years ago

I would encourage all users to make use of the documentation that we've provided and Google.

https://docs.openfaas.com/cli/templates/#nodejs-12-node12-of-watchdog-template

node12 is an official template and also in the template store. Please read the documentation.

yvz5 commented 4 years ago

Ofcourse I did read the documentation but the information is all over the place. Its really hard to follow.

I am using of-watchdog, in incubator you have templates listed which are using of-watchdog, there you have only node10. You have another organization which is really confusing, that contains the old watchdog templates. There you have node12 template. I compared both code and the only difference is node12 std watchdog version uses Promises to handle the function code. The rest is the same.

This problem happens when using both of the templates with of-watchdog. I've added ENV buffer_http="true" to the dockerfile without any luck.

yvz5 commented 4 years ago

I solved my problem by bypassing the bodyparser. If anyone has the same problem, you can find more info here: https://stackoverflow.com/questions/18710225/node-js-get-raw-request-body-using-express/21222540#21222540

alexellis commented 4 years ago

Of course I did read the documentation but the information is all over the place. Its really hard to follow.

I'm sorry I have no idea what you are talking about there. Can you elaborate?

The information is only in one place, in the docs which you can access from openfaas.com - the page below says to use the node12 template and that node10 is deprecated by nodejs.org.

https://docs.openfaas.com/cli/templates/#nodejs-12-node12-of-watchdog-template

I solved my problem by bypassing the bodyparser. If anyone has the same problem, you can find more info here: https://stackoverflow.com/questions/18710225/node-js-get-raw-request-body-using-express/21222540#21222540

We have already solved this problem, if you read the documentation more carefully you will see a RAW_BODY parameter which is only available on the node12 template. The effect of it? To bypass the body parser.

See below:

https://docs.openfaas.com/cli/templates/#nodejs-12-node12-access-to-the-raw-body