| const bytes = require('bytes'), | |
| express = require('express') | |
| let count = 0, | |
| totalBytes = 0 | |
| express() | |
| .use((req, res) => { | |
| count++ | |
| let size = 0 | |
| req.on('data', chunk => ( | |
| size += chunk.length | |
| )) | |
| req.on('end', () => { | |
| totalBytes += size | |
| const total = bytes( | |
| totalBytes, | |
| { unitSeparator: ' ' } | |
| ) | |
| console.log([ | |
| `[FLOOD] #${count}`, | |
| req.ip, | |
| `${req.method} ${req.url}`, | |
| `${size} bytes`, | |
| `Total: ${total}` | |
| ].join(' | ')) | |
| res.json({ | |
| requests: count, | |
| totalBytes, | |
| total | |
| }) | |
| }) | |
| }) | |
| .listen(7860) |