Created
April 1, 2015 04:52
-
-
Save mk30/bed112c00f4e900f5aa8 to your computer and use it in GitHub Desktop.
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 h = require('virtual-dom/h'); | |
| var str = require('virtual-dom-stringify'); | |
| var http = require('http'); | |
| var fs = require('fs'); | |
| var ecstatic = require('ecstatic'); | |
| var st = ecstatic(__dirname); | |
| var hyperstream = require('hyperstream'); | |
| var path = require('path'); | |
| var server = http.createServer(function (req, res) { | |
| if (req.url === '/') { | |
| fs.readdir(__dirname + '/images', onfiles); | |
| } | |
| else st(req, res); | |
| function onfiles (err, files) { | |
| var tree = h('div#content', [ | |
| h('h1', 'wow hello'), | |
| h('div.gallery', files.map(function (x) { | |
| return h('div', [ | |
| h('img', { | |
| src: 'images/' + x, | |
| height: 128 | |
| }) | |
| ]); | |
| })) | |
| ]); | |
| fs.createReadStream(path.join(__dirname, 'index.html')) | |
| .pipe(hyperstream({ '#content': str(tree) })) | |
| .pipe(res) | |
| ; | |
| res.end(str(tree)); | |
| } | |
| }); | |
| server.listen(6004); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment