Skip to content

Instantly share code, notes, and snippets.

@hakobera
Created March 20, 2015 09:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hakobera/57f303b60086f5f852ea to your computer and use it in GitHub Desktop.
Save hakobera/57f303b60086f5f852ea to your computer and use it in GitHub Desktop.
2015/3/21 時雨祭デモアプリ
node_modules
*.log
var koa = require('koa');
var slow = require('koa-slow');
var app = koa();
app.use(slow({ url: /^\/medium$/i, delay: 500 }));
app.use(slow({ url: /^\/slow$/i, delay: 1000 }));
app.use(function *() {
console.log(this.url);
if (this.path === '/error') {
throw new Error('something wrong...');
}
this.body = { result: this.path.substr(1) };
});
app.on('error', function (err, ctx) {
console.error('server error', err, ctx);
});
app.listen(process.env.PORT || 3000);
{
"name": "slow-and-fast",
"version": "1.0.0",
"description": "",
"scripts": {
"start": "node app.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"license": "MIT",
"dependencies": {
"koa": "^0.18.1",
"koa-slow": "^0.1.1"
},
"engines": {
"iojs": "1.6.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment