Search code examples
node.jsexpressaxioshttp-live-streaming

Forward ts of remote hls video in nodejs


router.get('/ts/:streamId/:ts',  (req, res, next)=> {
    var streamId = req.params["streamId"];
    var ts = req.params["ts"];
    var url = "http://192.168.0.193/hls/27f73cdf-c565-4328-a172-d23b1118e312/playout9.ts"

    axios.create({
        headers: { 'Authorization': 'Basic ' + req.session.bearer }
    }).get(url)
    .then(response => {
        res.end(response.data);
    });
});

I can download the file provided by the url from the browser and play it in the vlc player.

but when I use res.end(response.data); in my node.js server to forward, I cannot play the forwarded file, but it has a content size of about 1600KB.

I also referred to the following article and tried to edit content-type, but it didn't work: nodejs api does not forward response which received from another service

Any ideas are greatly appreciated.


Solution

  • Following the comment of Lawrence Cherone, I replace res.end(response.data); to response.data.pipe(res).