Closed Tan-nn closed 6 years ago
The request header doesn't appear to specify a content-type? I think bodyparser is probably causing it. What happens if you remove bodyParser? do you see the body as a string?
Hi @dougmoscrop Thanks for your reply.
I have rem // app.use(bodyParser());
, but got same result
Note: Nodejs8.10
I write some dummy code and testing with api-gateway, it can response body as my request
function respBuilder(statusCode = 200, body = '') {
return {
statusCode,
body: JSON.stringify(body)
};
}
exports.handler = async (event) => {
if (!event.body) {
return respBuilder(400, "Bad request nha may");
}
// TODO implement
return respBuilder(200, event.body)
};
Having the same issue with express.js
too.
Found the culprit, if you use express.js
>= v4, you have to app.use(require('body-parser').json())
to parse request body.
Taken from the following resource:
yeah there are numerous tests, and deployed apps, that are using body-parsing of json, I'm pretty sure this works unless you don't specify a content-type header (which is how it always works)
I'm print all ctx but can not find body
serverless:
request body:
{"userId": 123}
but ctx:p/s: using LAMBDA_PROXY