birdpack 1.0.7 → 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.
Files changed (2) hide show
  1. package/lib/server.js +30 -3
  2. 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 = {
@@ -246,9 +275,6 @@ module.exports = class{
246
275
  let out = `[${status}] - ${text}`;
247
276
  console.log(out);
248
277
  }
249
- traffic(c){
250
- this.log('client',`${this.getFormattedDateTime()} ${c.status} ${c.method} ${c.path} ${c.ip} ${c.get('user-agent')}`);
251
- }
252
278
  getFormattedDateTime(){
253
279
  let now = new Date();
254
280
 
@@ -383,3 +409,4 @@ module.exports = class{
383
409
  return ()=>{};
384
410
  }
385
411
  }
412
+
package/package.json CHANGED
@@ -3,6 +3,6 @@
3
3
  "description": "BirdPack web framework is a tool for web server via TCP HTTP supporting websocket focusing on speed.",
4
4
  "author":"R938",
5
5
  "license":"R938",
6
- "version":"1.0.7",
6
+ "version":"1.0.8",
7
7
  "main": "index.js"
8
8
  }