Skip to content

Instantly share code, notes, and snippets.

@akb
Created November 9, 2011 18:03
Show Gist options
  • Select an option

  • Save akb/1352285 to your computer and use it in GitHub Desktop.

Select an option

Save akb/1352285 to your computer and use it in GitHub Desktop.
a web server as a series of tubes
var tubes = require('tubes');
var model = new tubes.model.Model({
name: 'Bob Dobbs',
age: 34,
favoriteColor: 'red'
});
model.on('updated', function (data) {
tubes.emit('data updated', model.fields);
});
tubes('/', 'root').connect()
.toTemplate('detail.html', model.fields);
tubes('/form', 'form').connect()
.get.toTemplate('form.html', model.fields)
.post.toPostRedirect('/', function (data, complete) {
model.set(data);
complete();
});
tubes('/style.com', 'style').connect()
.toFileStream('./approot/style.css', 'text/css');
tubes(/^\/js\/(.*)$/, 'js').connect()
.toFileStream(function () {
return './approot/js/' + this[0];
}, 'text/javascript');
tubes.sendInternetsThru(3000);
@akb

akb commented Nov 9, 2011

Copy link
Copy Markdown
Author

live demo at http://lexik.us:3000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment