Last active
December 22, 2015 17:29
-
-
Save AleksandrT/6506564 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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