为什么在快递中使用此配置会收到Req.Req嵌套请求?

问题描述

编辑:如果嵌套请求或响应有问题。检查参数的顺序,或使用express.router({margeParams:true})选项。

我的请求被另一个对象请求包装。

我必须以这种方式访问​​'req.body'-> req.req.body 那是因为我的配置吗?

我有一个具有此配置的快递服务器:

import express from 'express';
import routes from './routes.js';

const app = express();

app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use('/api',routes);

server.listen(80);

这是routes.js

import express from 'express';
import webhooksRoutes from './controllers/Webhooks/webhooksRoutes.js';

const routes = express.Router();
routes.use('/webhooks',webhooksRoutes);

这是webhooksRoutes.js

import express from 'express';
const userRoutes = express.Router();

userRoutes.post('/orders',orderWebhooks);

这是orderWebhooks.js

const wirecardOrdersWebhooks = (res,req) => {
    // here the "real" request that come to the server is in res.res
    const realReq = req.req
}

解决方法

在这里,第一个参数应该是res之前的req;

const wirecardOrdersWebhooks = (req,res) => {
   // here the "real" request that come to the server is in res.res
   const realReq = req.body
}

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...