-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebugcon.js
More file actions
63 lines (55 loc) · 1.61 KB
/
debugcon.js
File metadata and controls
63 lines (55 loc) · 1.61 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import debug from 'debug';
// Wrapper function
function log(con, req, res, next, base, nobody = false) {
if (base === undefined || base == null) {
base = ""
}
con('Request:', req.method, base + req.path, req.query);
const originalSend = res.send;
const originalJson = res.json;
// Override res.send to capture the body
res.send = (body) => {
res.send = originalSend
res.json = originalJson;
if (nobody) {
con('Response: [' + res.statusCode + '] ')
} else {
con('Response: [' + res.statusCode + '] ', body);
}
originalSend.call(res, body);
};
// Override res.json to capture the body
res.json = (body) => {
res.send = originalSend;
res.json = originalJson;
con('Response: (JSON) [' + res.statusCode + '] ');
if (!nobody) {
con(body)
}
originalJson.call(res, body);
};
return [originalSend, originalJson]
}
// Wrapper function
function unlog(con, req, res, next, base, originalSend, originalJson) {
if (base === undefined || base == null) {
base = ""
}
con('EndZone:', req.method, base + req.path, req.query);
res.send = originalSend;
res.json = originalJson;
}
export default {
log: log,
unlog: unlog,
svCon: debug('red-engine:server'),
dbCon: debug("red-engine:database"),
authCon: debug("red-engine:route/auth"),
postCon: debug("red-engine:route/post"),
playCon: debug("red-engine:route/post:play"),
signalCon: debug("red-engine:route/post:signal"),
userCon: debug("red-engine:route/user"),
vgdCon: debug("red-engine:route/vgd"),
ssCon: debug("red-engine:route/session"),
dgCon: debug("red-engine:debug"),
}