Skip to content

Instantly share code, notes, and snippets.

@AleksandrT
Last active December 22, 2015 17:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AleksandrT/6506564 to your computer and use it in GitHub Desktop.
Save AleksandrT/6506564 to your computer and use it in GitHub Desktop.
app.get('/video/:html', function (req, res) {
res.send("<!DOCTYPE html><html lang=\"en\">" +
"<head><title>Video</title>" +
"<link href='http://vjs.zencdn.net/4.1/video-js.css' rel='stylesheet'>" +
"<script src='http://vjs.zencdn.net/4.1/video.js'></script>" +
"</head>" +
"<body><center>" +
"<video id='video' class='video-js vjs-default-skin'" +
" controls preload='auto' width='640' height='264'" +
" source src='' type='video/mp4' />" +
"</center></body></html>");
});
app.get('/video/:word', function (req, res) {
var _word = req.params.word;
db.collection('words').findOne({ 'word': _word }, function (err, result) {
if (!err || result.count === 1) {
var path = __dirname + '\\videos\\' + result._id + "\\" + result.videos[0].type;
fs.exists(path, function(exists) {
if (exists) {
res.writeHead(200, { 'Content-Length': result.videos[0].size, 'Content-Type': 'video/mp4' });
var stream = fs.createReadStream(path);
stream.pipe(res);
}
});
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment