-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalytics.js
More file actions
41 lines (38 loc) · 831 Bytes
/
analytics.js
File metadata and controls
41 lines (38 loc) · 831 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
32
33
34
35
36
37
38
39
40
41
const db = require('./db');
async function log(req)
{
const logPkg = {
baseUrl: req.baseUrl,
method: req.method,
originalUrl: req.originalUrl,
query: JSON.stringify(req.query),
path: req.path,
params: JSON.stringify(req.params),
ip: req.ip
};
console.log('///REQUEST///');
console.log(logPkg.ip);
console.log(logPkg.method, logPkg.path);
if(logPkg.query !== '{}')
{
console.log(logPkg.query);
}
if(logPkg.params !== '{}')
{
console.log(logPkg.params);
}
console.log('///////');
await db.Logs.create(logPkg);
}
async function download(req, target)
{
const logPkg = {
target: target,
ip: req.ip
};
await db.Downloads.create(logPkg);
}
module.exports = {
log,
download
};