Closed baenacoco closed 3 years ago
You can't send the request as a stream because the POST body stream is processed by the text body parser. And because the body is not an object, you should use mergeParams: false
in route options:
greeter.service.js
xmlExample: {
rest: {
method: "POST",
path: "/xml/example",
//type: "stream",
},
async handler(ctx) {
return ctx.params.body;
},
}
route options in api.service
bodyParsers: {
json: {
strict: false,
limit: "1MB"
},
urlencoded: {
extended: true,
limit: "1MB"
},
text: {
type: "application/xml",
},
},
mergeParams: false,
// Mapping policy setting. More info: https://moleculer.services/docs/0.14/moleculer-web.html#Mapping-policy
mappingPolicy: "all", // Available values: "all", "restrict"
Result:
Prerequisites
Please answer the following questions for yourself before submitting an issue.
Current Behavior
Example code:
The xmlExample return in production mode the TypeError. It's working in develop mode
npm run dev
Expected Behavior
I expected to get the same XML in the petition.
Failure Information
Please view the logs.
Steps to Reproduce
Please provide detailed steps for reproducing the issue.
moleculer init project moleculer-demo
npm run dc:up
and check with postman or a preferred desktop API client.Context
Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.
Failure Logs