CodeGenieApp / CodeGenieApp/serverless-express

Incorrect Data (empty body) returned through req: lambda + API gateway

Abierto
#467 1 comentario 2 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
JavaScript
Estrellas
5.3k
Forks
676
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

### app.post("/path/path", (req, res) => { }

I am not sure what exactly is the issue is, but it seems that my **req** variable contains weird data from aws- api gateway. When I try log the contents I get a circular error. The data exists in the event variable with the following code in my index .js:

```
const awsServerlessExpress = require('aws-serverless-express');
const app = require('./app');

const server = awsServerlessExpress.createServer(app);

exports.handler = (event, context) => {
console.log(`EVENT: ${JSON.stringify(event)}`);
return awsServerlessExpress.proxy(server, event, context, 'PROMISE').promise;
};

```

Then in my app.js i have the following code:

``` // app modules
var express = require("express");
var bodyParser = require("body-parser");
var awsServerlessExpressMiddleware = require("aws-serverless-express/middleware");

// declare a new express app
var app = express();
app.use(bodyParser.json());
app.use(awsServerlessExpressMiddleware.eventContext());

// Enable CORS for all methods
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "*");
next();
});


app.post("/NotifyUrl-crprod/payfast", (req, res) => {

console.log("body" + Object.keys(req), Object.values(req));
console.log("body1" + req);
})
```
The req parameter contains stuff except the data that was actually sent through from api gateway, i.e. the data (body) doesn't exist in the **req**, even though it exists in **event** . The screenshots below are printouts of the keys and values that are printed out and the event variable data . These keys are not the issue, the issue is that the desired data doesn't appear at all **req.body** is empty. logging out the **req** will through a circular reference error which is okay, but the desired data is not present.

These are the different dependency version being used:
```
"aws-serverless-express": "^3.4.0",
"body-parser": "^1.17.1",
"express": "^4.15.2",
```

The below event printout screenshot is only a fraction of the full data that is contained in req.
Screenshot 2021-09-28 at 13 22 15

![Screenshot 2021-09-28 at 13 26 43](https://user-images.githubusercontent.com/64155956/135079103-d57392ba-ed83-4dba-bc72-d6f58b888d5a.jpg)

Guía de contribución

Abrir la guía de contribución

Línea de trabajo

Comienza con index.js y app.js, y luego compara el evento de API Gateway registrado con los datos expuestos al handler de Express en /NotifyUrl-crprod/payfast. Reproduce la solicitud POST y verifica si req.body contiene el payload enviado; se considera hecho cuando el cuerpo de la solicitud está disponible en el handler o se ha identificado el límite de integración que provoca que esté ausente.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
aws, express, javascript, node.js
Área
api, backend, cloud
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Necesita aclaración
Aptitud para principiantes
30/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.