forked from amethystnetwork-dev/Incognito
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalytics.js
33 lines (31 loc) · 867 Bytes
/
analytics.js
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
32
33
import crypto from 'node:crypto'
export default function analytics(req, res, data) {
switch(req.url) {
case '/data/visit':
data.live++
data.visits++
if(data.peak < data.live) data.peak = data.live
res.end('OK')
break;
case '/data/create-id':
res.end(crypto.randomUUID())
break;
case '/data/keep-alive':
res.end()
break;
case '/data/destroy':
removeVisit(req, data)
res.end()
break;
case '/data/data':
res.writeHead(200, { 'Content-Type': 'application/json' })
res.end(JSON.stringify(data))
break;
default:
res.writeHead(404)
res.end('404')
}
}
function removeVisit(req, data) {
data.live = data.live - 1
}