Earlier, I was able to pipe the response of another api call to Next.js api response as follows
export default async function (req, res) {
// prevent same site/ obfuscate original API
// some logic here
fetch(req.body.url).then(r => {
r.body.pipe(res);
}).catch(err => {
console.log(err);
res.status(500).send("Invalid Url");
})
}
It worked fine. But now the response.body from fetch API does not have pipe method. Rather, it has pipeTo and pipeThrough methods. And the Next.js res:NextApiResponse, is not assignable to WritableStream.
I also tried creating blob (await r.blob()) and using res.send(blob) and res.send(blob.strem()). It seems to work at first but the data received by front end is not proper (Basically fetch().then((res) => res.blob()).then((blob) => URL.createObjectURL(blob))) will give corrupt result).