birdpack 1.0.6 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/server.js +34 -6
- package/package.json +1 -1
package/lib/server.js
CHANGED
|
@@ -37,6 +37,35 @@ module.exports = class{
|
|
|
37
37
|
}else{
|
|
38
38
|
this.log = ()=>{};
|
|
39
39
|
}
|
|
40
|
+
|
|
41
|
+
let traffic = this.opt.traffic;
|
|
42
|
+
if(typeof traffic !== 'string'){
|
|
43
|
+
traffic = '$time $status $method $path $ip $head(user-agent)';
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
let useTraffic = traffic.replace(/\$[a-zA-Z0-9\(\)\-]*/g, (a)=>{
|
|
47
|
+
if(a == '$time'){
|
|
48
|
+
return '${time}';
|
|
49
|
+
}else if(a == '$status'){
|
|
50
|
+
return '${c.status}';
|
|
51
|
+
}else if(a == '$method'){
|
|
52
|
+
return '${c.method}';
|
|
53
|
+
}else if(a == '$path'){
|
|
54
|
+
return '${c.path}';
|
|
55
|
+
}else if(a == '$ip'){
|
|
56
|
+
return '${c.ip}';
|
|
57
|
+
}else if(a == '$body'){
|
|
58
|
+
return '${typeof c.body == "object" ? JSON.stringify(c.body) : (typeof c.body == "string" ? c.body : "NULL")}';
|
|
59
|
+
}else if(a.slice(0,5) == '$head'){
|
|
60
|
+
let myhead = a.slice(6,-1);
|
|
61
|
+
return '${c.get("' + myhead + '") || "NULL"}';
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
let callTraffic = new Function("time", "c", `return \`${useTraffic}\``);
|
|
66
|
+
this.traffic = (c)=>{
|
|
67
|
+
this.log('client', callTraffic(this.getFormattedDateTime(), c));
|
|
68
|
+
}
|
|
40
69
|
}
|
|
41
70
|
argv(){
|
|
42
71
|
let cmd = {
|
|
@@ -236,8 +265,9 @@ module.exports = class{
|
|
|
236
265
|
}
|
|
237
266
|
|
|
238
267
|
this.logServer('server', `The server is collecting logs via (${this.opt.log})`);
|
|
239
|
-
|
|
240
|
-
|
|
268
|
+
port = port || this.opt.port || process.env.PORT || 3000;
|
|
269
|
+
this.server.listen(port, host, ()=>{
|
|
270
|
+
this.logServer('server', `Started on server(${this.opt.use}) port(${port})`);
|
|
241
271
|
});
|
|
242
272
|
}
|
|
243
273
|
}
|
|
@@ -245,9 +275,6 @@ module.exports = class{
|
|
|
245
275
|
let out = `[${status}] - ${text}`;
|
|
246
276
|
console.log(out);
|
|
247
277
|
}
|
|
248
|
-
traffic(c){
|
|
249
|
-
this.log('client',`${this.getFormattedDateTime()} ${c.status} ${c.method} ${c.path} ${c.ip} ${c.get('user-agent')}`);
|
|
250
|
-
}
|
|
251
278
|
getFormattedDateTime(){
|
|
252
279
|
let now = new Date();
|
|
253
280
|
|
|
@@ -381,4 +408,5 @@ module.exports = class{
|
|
|
381
408
|
}
|
|
382
409
|
return ()=>{};
|
|
383
410
|
}
|
|
384
|
-
}
|
|
411
|
+
}
|
|
412
|
+
|