Skip to content

Instantly share code, notes, and snippets.

@asoltys
Created June 24, 2021 23:20
Show Gist options
  • Save asoltys/a7ee61da29a233c3977ac59f842e68bb to your computer and use it in GitHub Desktop.
Save asoltys/a7ee61da29a233c3977ac59f842e68bb to your computer and use it in GitHub Desktop.
app.get('/file/:name', function (request, reply) {
let type = 'application/json';
const { name } = request.params;
const stream = fs.createReadStream(`file/${name}`);
if (name.includes('m3u8')) type = 'application/vnd.apple.mpegurl';
if (name.includes('ts')) type = 'video/MP2T';
reply.header('Content-Type', type).send(stream.pipe(transform));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment