I'm trying to use express to pipe a response to my main server since for some reason subtitles/captions don't work if they are local (???). I have this code so far, but I get the error Error [ERR_STREAM_CANNOT_PIPE]: Cannot pipe, not readable.
app.get("/subtitle*", async(req, res) => {
if (!req.params || !req.params[0]) {
return;
}
let id = req.params[0];
if (!id) {
return;
}
id = id.split("/")[1];
db.serialize(async function () {
await db.get('SELECT * FROM shows WHERE id = ?', [id], async function (err, rows, fields) {
if (err) reject(err);
if (!rows) {
return;
} else {
let path = ...;
let stream = fs.createReadStream(path);
console.log(stream);
res.set('Content-Type', 'text/vtt');
res.pipe(stream);
res.end();
}
});
});
});
Then in my express page, I use HTML and jQuery to send an HTTP request and set the track src like this:
JavaScript
$.get(api + '/subtitle/${id}', function(data) {
console.log(data);
var video = api + '/subtitle/${id}';
$('track').attr('src', video);
$('#sublink').attr('href', video);
});
HTML
<track src="" kind="subtitle" srclang="en-US" label="English" />