express.io.js 1.0.1152 → 1.0.1611

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.
@@ -18,8 +18,9 @@ class express {
18
18
  this.express = $.express ();
19
19
  this.config = config;
20
20
  this.host = this.config.host || "0.0.0.0";
21
- this.port = process.env.PORT || this.config.port || 3000;
21
+ this.port = this.config.port || process.env.PORT || 3000;
22
22
  this.serve = this.config.static || {dotfiles: "ignore"}
23
+ Event.proto (this);
23
24
  }
24
25
  static (path = "public", option) {
25
26
  var serve = option || this.serve;
@@ -28,11 +29,12 @@ class express {
28
29
  }
29
30
  setup (context) {
30
31
  var io = function (app) {
31
- return function (r, respond, next) {
32
+ return async function (r, respond, next) {
32
33
  var http_d = {request: r, response: respond}
33
34
  var {request, response} = express.io (app, http_d);
34
35
  app.__ = {request, response}
35
- express.setup (app.__.request, app.__.response, next, http_d);
36
+ await express.setup.call (app, app.__.request, app.__.response);
37
+ express.security.call (app, app.__.request, app.__.response);
36
38
  context (app.__.request, app.__.response, next, http_d);
37
39
  }
38
40
  }
@@ -41,11 +43,7 @@ class express {
41
43
  }
42
44
  io (app, context) {
43
45
  return function (request, response, next) {
44
- if (app.__.request.error.length) {
45
- if (app.__.request.error.includes ("forbidden")) app.__.response.error.forbidden ();
46
- else app.__.response.error ();
47
- }
48
- else context (app.__.request, app.__.response, next, {request, response});
46
+ context (app.__.request, app.__.response, next, {request, response});
49
47
  }
50
48
  }
51
49
  use (... context) {
@@ -100,6 +98,10 @@ express.request = function (app, http_d) {
100
98
  request.get = function (... get) {
101
99
  return http_d.request.get (... get);
102
100
  }
101
+ if (request.visitor = {}) {
102
+ request.visitor.ip = {address: "127.0.0.1"}
103
+ request.visitor.browser = request.header ["user-agent"];
104
+ }
103
105
  return request;
104
106
  }
105
107
 
@@ -114,6 +116,7 @@ express.response = function (app, request, http_d) {
114
116
  response.output = new $.html ();
115
117
  response.error = function (code = 500) { http_d.response.status (code).send (URL.header.status.code [code]); }
116
118
  response.error.forbidden = function (code = 403) { http_d.response.status (code).send (URL.header.status.code [code]); }
119
+ response.error.found = function (code = 404) { http_d.response.status (code).send (URL.header.status.code [code]); }
117
120
  return response;
118
121
  }
119
122
 
@@ -127,7 +130,16 @@ express.response = function (app, request, http_d) {
127
130
  * xxx://xxx.xxx.xxx/xxx
128
131
  */
129
132
 
130
- express.setup = function (request, response, next, http_d) {
133
+ express.security = function (request, response) {
134
+ this.emit ("security", request, response);
135
+ if (request.error.length) {
136
+ if (request.error.includes ("forbidden")) response.error.forbidden ();
137
+ else if (request.error.includes ("found")) response.error.found ();
138
+ else response.error ();
139
+ }
140
+ }
141
+
142
+ express.setup = function (request, response) {
131
143
  if (true) {
132
144
  response.output.set ("language", "en");
133
145
  response.output.set ("html:attribute", {translate: "no", prefix: "og: http://ogp.me/ns#"});
@@ -136,6 +148,9 @@ express.setup = function (request, response, next, http_d) {
136
148
  response.output.set ("debug", JSON.pretty (request.header));
137
149
  if (false) response.output.set ("meta", {attribute: {name: "adsterra", content: "ads"}});
138
150
  }
151
+ return new Promise (function (resolve, reject) {
152
+ resolve (true);
153
+ });
139
154
  }
140
155
 
141
156
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "express.io.js",
3
3
  "description": "Hello World",
4
- "version": "1.0.1152",
4
+ "version": "1.0.1611",
5
5
  "author": "Seindi Rahmat Barus <xseindi@gmail.com>",
6
6
  "contributors": [
7
7
  "Seindi Rahmat Barus <xseindi@gmail.com>"
@@ -22,6 +22,6 @@
22
22
  ],
23
23
  "dependencies": {
24
24
  "express": "^5.2.1",
25
- "script.io.js": "^1.0.1152"
25
+ "script.io.js": "^1.0.1611"
26
26
  }
27
27
  }