【发布时间】:2021-04-19 06:00:04
【问题描述】:
我已经设法让中间件在 Strapi 中工作。但是,我在请求中看不到正文。
在 /middlewares/getEmail/index.js 里面,我有
module.exports = (strapi) => {
return {
initialize: function (cb) {
strapi.app.use(async (ctx, next) => {
if (ctx.method === "POST" && ctx.url === "/email-leads") {
console.log(ctx);
}
await next();
});
},
};
};
和 ctx 请求日志:
request: {
method: 'POST',
url: '/email-leads',
header: {
'content-type': 'application/json',
accept: 'application/json',
'user-agent': 'PostmanRuntime/7.26.8',
'postman-token': 'xxx',
host: 'localhost:1337',
'accept-encoding': 'gzip, deflate, br',
connection: 'keep-alive',
'content-length': '33'
}
},
这是我在此应用程序上编写的唯一中间件。在 /config/middleware.js 中,我有
module.exports = {
load: {
before: ["getEmail", "responseTime", "logger", "cors", "responses", "gzip"],
order: ["parser"],
after: ["router"],
},
settings: {
getEmail: {
enabled: true,
},
},
};
我阅读了这个 koa-body/unparsed.js 来阅读正文,但 ctx.request 中实际上没有正文。感谢您的帮助。
【问题讨论】: