Created
March 20, 2015 09:45
-
-
Save hakobera/57f303b60086f5f852ea to your computer and use it in GitHub Desktop.
2015/3/21 時雨祭デモアプリ
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
node_modules | |
*.log |
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('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); | |
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
{ | |
"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