Created
November 9, 2011 18:03
-
-
Save akb/1352285 to your computer and use it in GitHub Desktop.
a web server as a series of tubes
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 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); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
live demo at http://lexik.us:3000