Closed rishighan closed 3 years ago
You can't access res
in services because it's non-serializable only in API gateway. To return a stream, just return it in the service. but I don't know how it should transfer with socket.io.
So I made a change, I created a custom function in an alias in my API gateway.
I have access to the res
object here. The question is how to I call it with broker.call
?
aliases: {
async "POST getComicCovers"(req, res) {
const {
extractionOptions,
walkedFolders
} =
req.body;
switch (extractionOptions.extractionMode) {
case "bulk":
map(
walkedFolders,
async (folder, idx) => {
let foo = await extractArchive(
extractionOptions,
folder
);
// console.log("levar", foo);
let jsonStream =
new JsonStreamStringify({
foo,
});
jsonStream.pipe(res);
}
);
case "single":
return await extractArchive(
extractionOptions,
walkedFolders[0]
);
default:
console.log(
"Unknown extraction mode selected."
);
return {
message:
"Unknown extraction mode selected.",
errorCode: "90",
data: `${extractionOptions}`,
};
}
},
},
I have a
socket.io
setup, where I am emitting an event from a Moleculer service and theexpress
client app responds to it. My action creates a stream from the JSON and I want to pipe it into the response object.Currently I am just returning the stream. My question is: Do I have access to the
response
object from my action that I can pipe the stream into? If not, what are my options?My action in
import.service.ts
My
api.service.ts