Last active
April 26, 2020 16:01
-
-
Save kuanyui/363d2a7c12704495a58bb704e4c06637 to your computer and use it in GitHub Desktop.
Weekend bed potato generator. Lie on bed with tablet all the day.
This file contains hidden or 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
| var http = require('http') | |
| var path = require('path') | |
| var contentDisposition = require('content-disposition') | |
| var finalhandler = require('finalhandler') | |
| var serveStatic = require('serve-static') | |
| var serveIndex = require('serve-index') | |
| const ROOT = path.join(process.env.HOME, '###TO/YOUR/VIDEO/DIRECTORY/') | |
| console.log(ROOT) | |
| var index = serveIndex(ROOT, {'icons': true}) | |
| var serve = serveStatic(ROOT, { | |
| 'index': false, | |
| 'setHeaders': setHeaders | |
| }) | |
| // Set Content-Disposition to inline (always open & play video in browser instead of download it) | |
| function setHeaders (res, path) { | |
| res.setHeader('Content-Disposition', contentDisposition(path, {type: 'inline'})) | |
| } | |
| var server = http.createServer(function onRequest(req, res){ | |
| var done = finalhandler(req, res) | |
| serve(req, res, function onNext(err) { | |
| if (err) { return done(err) } | |
| index(req, res, done) | |
| }) | |
| }) | |
| server.listen(8000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment