-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
31 lines (27 loc) · 678 Bytes
/
server.js
File metadata and controls
31 lines (27 loc) · 678 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
let e = require('express'),
a = e(),
p = process.env.PORT || 8080,
r = new (require('randbytes')).urandom.getInstance(),
b = process.env.BYTES || 5000,
u = process.env.MAX_BYTES || 500000
a.get('/', (req, res) => {
r.getRandomBytes(b, (b) => {
res.header('Content-Type', 'text/html')
res.send(b)
})
})
a.get('/:b', (req, res) => {
let b2 = null
try {
b2 = parseInt(req.params.b, 10)
if(!b2 || b2 < 0) { b2 = b }
b2 = Math.min(b2, u)
} catch (e) {
b2 = b
}
r.getRandomBytes(b2, (b) => {
res.header('Content-Type', 'text/html')
res.send(b)
})
})
a.listen(p, () => { console.log(`Listening on port ${p}.`) })