根据API文档,要从POST请求接收json作为formData,必须使用主体解析器。我已经在网关服务中声明了它,但是我仍然无法在我的操作中接收到formData。
api.service.js
module.exports = {
name: "api",
mixins: [ApiGateway],
settings: {
port: process.env.PORT || 3000,
routes: [{
path: "/api",
aliases: {
"POST users": "users.insertUser",
},
//The API Documentation recomends using the body-parser here
bodyParsers: {
json: true,
urlencoded: { extended: true }
},
}],
// In some example they also set the body-parser here
bodyParsers: {
json: true,
urlencoded: { extended: true }
},
},
};在actions service.insertUser操作中,我应该以ctx.params的身份接收req.body,但它始终为空
我的users.service.js
actions: {
insertUser: {
handler(ctx) {
this.logger.info("posting", ctx.params); // -> prints {} instead of the formData
}
}发布于 2019-11-28 23:32:28
你有没有试过给病人
insertUser: {
auth: "required",
params: {
function_id: { type: "string" },
role_id: { type: "string" },
},
handler(ctx) { ctx.params.role_id

https://stackoverflow.com/questions/58983649
复制相似问题