Skip to content

Instantly share code, notes, and snippets.

@mk30
Created April 1, 2015 04:52
Show Gist options
  • Select an option

  • Save mk30/bed112c00f4e900f5aa8 to your computer and use it in GitHub Desktop.

Select an option

Save mk30/bed112c00f4e900f5aa8 to your computer and use it in GitHub Desktop.
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