-
Notifications
You must be signed in to change notification settings - Fork 672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
req.body returns a Buffer #347
Comments
Hi @jeremydrichardson, could you provide some information such as:
|
Yep.
but I have updated recently so yarn.lock entry is
Using postman POST with raw json payload
Returns
Let me know if you have any other questions. |
Well, sort of good and bad news. Somehow our app started working again and the req.body is fine. It makes me wary that I'm not sure what it was but we were having some issue with the version of this package so maybe that's all it was. I'll close this for now and re-open if the issue reappears. |
Hi, I am currently experiencing the same issue. In my use case, I trigger a Lambda function directly (not via API Gateway) but pass an event that looks like an AWS API Gateway V1 proxy event. When I log the event before I have found a way to remove the error by changing function getEventBody ({
event,
body = event.body,
isBase64Encoded = event.isBase64Encoded
}) {
return Buffer.from(body, isBase64Encoded ? 'base64' : 'utf8');
} and just completely removing the conversion to a Buffer: function getEventBody ({
event,
body = event.body,
isBase64Encoded = event.isBase64Encoded
}) {
return body;
} I am using version
import serverlessExpress from "@vendia/serverless-express";
import { createApp } from "./app";
let serverlessExpressInstance: any;
async function setup() {
const app = await createApp();
serverlessExpressInstance = serverlessExpress({ app });
}
export async function handler(event: any, context: any) {
console.log(JSON.stringify({ event }));
if (!serverlessExpressInstance) {
await setup();
}
return serverlessExpressInstance(event, context);
} {
"body": "{\"name\":\"Soenke\"}",
"resource": "/{proxy+}",
"path": "v1/echo.echo",
"httpMethod": "POST",
"queryStringParameters": {
"foo": "bar"
},
"multiValueQueryStringParameters": {
"foo": [
"bar"
]
},
"pathParameters": {
"proxy": "v1/echo.echo"
},
"stageVariables": {
"baz": "qux"
},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate, br",
"Content-Type": "application/json",
"Accept-Language": "en-US,en;q=0.8",
"Cache-Control": "max-age=0"
},
"multiValueHeaders": {},
"requestContext": {
"body": "{\"name\":\"Soenke\"}"
}
} I am happy to provide more information if needed! |
This is happening to us as well, 4.10.1 |
Hi guys, I hope this solution to be useful for you...
app.post("/email",(req, res)=>{ |
Hi there, |
This is still happening and breaks existing express applications. |
I added this middleware as a temp workaround
|
The solution provided by @manuelhonoredesousa worked for me if you use this other package as well https://github.com/dougmoscrop/serverless-http/blob/master/docs/EXAMPLES.md |
I've been following this thread pretty closely as we have been seeing similar problems. It turns out our problem was that our Maybe an enhancement request for this library - if we are trying to make the |
For some reason in some version change (apologize I don't know from which version this started, but sometime after the switch from AWS to Vendia as the maintainer), req.body now returns a Buffer.
Is this intended? This is even after using bodyParser.json() as middleware.
I have found that I can use
That seems to give me a better response but takes place outside the Express environment.
I'm curious as to why req.body returns a Buffer instead of a json object.
The text was updated successfully, but these errors were encountered: