Created
July 23, 2014 01:42
-
-
Save dustinsmith1024/d353a93e07d78a5d233e to your computer and use it in GitHub Desktop.
Simple Koa Example
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 koa = require('koala'); | |
var app = koa(); | |
app.use(function *(){ | |
//console.log(this.req, this.path); | |
if(this.path==='/hey'){ | |
this.body = yield dogs; | |
}else{ | |
if(this.path!=='/favicon.ico'){ | |
// don't call the function...it needs to return a function | |
var b = yield home; | |
this.body = b; | |
} | |
} | |
}); | |
function dogs(cb){ | |
cb(null, "Sup Dog"); | |
} | |
// called functions take a callback | |
function home(cb){ | |
setTimeout(function(){ | |
return cb(null, "Home!!"); | |
}, 300); | |
} | |
app.listen(3000); | |
// run with harmony | |
// node --harmony index.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment