Skip to content

Instantly share code, notes, and snippets.

@nikezono
Created June 24, 2015 08:10
Show Gist options
  • Select an option

  • Save nikezono/253d87defb3f3e91c89c to your computer and use it in GitHub Desktop.

Select an option

Save nikezono/253d87defb3f3e91c89c to your computer and use it in GitHub Desktop.
シンプルな性的ファイル配信サーバ
# Node.js API
path = require 'path'
fs = require 'fs'
# NPM modules
express = require 'express'
stream = require 'connect-stream'
app = express()
# Config
loadPath = process.env.STATIC_FILE_PATH || 'statics'
app.use(stream(path.resolve(loadPath)))
app.set('view engine', 'jade')
app.get '/', (req,res)->
res.render "index",
files: fs.readdirSync(path.resolve loadPath)
app.get '/:filename', (req,res)->
res.render 'play',
title: req.params.filename
app.get '/:filename/stream', (req,res)->
res.stream req.params.filename
app.listen process.env.PORT || 3070
h1 files
ul
for file in files
li
a(href="/"+file)= file
h1= title
video(width="720", height="480", controls)
source(src="/"+title+"/stream")
|ブラウザがvideoタグをサポートしていないです🍣
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment