Update index.js
Browse files
index.js
CHANGED
|
@@ -1,34 +1,28 @@
|
|
| 1 |
const bytes = require('bytes'),
|
| 2 |
-
express = require('express')
|
| 3 |
-
|
| 4 |
-
let count = 0,
|
| 5 |
-
totalBytes = 0
|
| 6 |
|
| 7 |
express()
|
| 8 |
.use((req, res) => {
|
| 9 |
-
|
| 10 |
let size = 0
|
| 11 |
-
req.on('data', chunk => (
|
| 12 |
size += chunk.length
|
| 13 |
))
|
| 14 |
req.on('end', () => {
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
{ unitSeparator: ' ' }
|
| 19 |
)
|
| 20 |
console.log([
|
| 21 |
-
`[FLOOD] #${
|
| 22 |
req.ip,
|
| 23 |
`${req.method} ${req.url}`,
|
| 24 |
`${size} bytes`,
|
| 25 |
-
`Total: ${total}`
|
| 26 |
].join(' | '))
|
| 27 |
-
res.json(
|
| 28 |
-
requests: count,
|
| 29 |
-
totalBytes,
|
| 30 |
-
total
|
| 31 |
-
})
|
| 32 |
})
|
| 33 |
})
|
| 34 |
.listen(7860)
|
|
|
|
| 1 |
const bytes = require('bytes'),
|
| 2 |
+
express = require('express'),
|
| 3 |
+
stats = { bytes: 0, req: 0 }
|
|
|
|
|
|
|
| 4 |
|
| 5 |
express()
|
| 6 |
.use((req, res) => {
|
| 7 |
+
stats.req++
|
| 8 |
let size = 0
|
| 9 |
+
req.on('data', (chunk) => (
|
| 10 |
size += chunk.length
|
| 11 |
))
|
| 12 |
req.on('end', () => {
|
| 13 |
+
stats.bytes += size
|
| 14 |
+
stats.total = bytes(
|
| 15 |
+
stats.bytes,
|
| 16 |
{ unitSeparator: ' ' }
|
| 17 |
)
|
| 18 |
console.log([
|
| 19 |
+
`[FLOOD] #${stats.req}`,
|
| 20 |
req.ip,
|
| 21 |
`${req.method} ${req.url}`,
|
| 22 |
`${size} bytes`,
|
| 23 |
+
`Total: ${stats.total}`
|
| 24 |
].join(' | '))
|
| 25 |
+
res.json(stats)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
})
|
| 27 |
})
|
| 28 |
.listen(7860)
|