Skip to content

Instantly share code, notes, and snippets.

@dustinsmith1024
Created July 23, 2014 01:42
Show Gist options
  • Save dustinsmith1024/d353a93e07d78a5d233e to your computer and use it in GitHub Desktop.
Save dustinsmith1024/d353a93e07d78a5d233e to your computer and use it in GitHub Desktop.
Simple Koa Example
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