express.io.js 1.0.1248 → 1.22.1015

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.
@@ -16,24 +16,29 @@ $.express = require ("express");
16
16
  class express {
17
17
  constructor (config) {
18
18
  this.express = $.express ();
19
- this.config = config;
19
+ this.config = config || express.config || {}
20
+ this.config.static = this.config.static || {dotfiles: "ignore"}
20
21
  this.host = this.config.host || "0.0.0.0";
21
22
  this.port = this.config.port || process.env.PORT || 3000;
22
- this.serve = this.config.static || {dotfiles: "ignore"}
23
+ this.dir = {name: this.config.dir}
24
+ this.dir.src = $.path.join (this.dir.name, "src")
25
+ this.dir.db = $.path.join (this.dir.src, "db")
26
+ this.dir.theme = $.path.join (this.dir.src, "theme")
27
+ Event.proto (this);
23
28
  }
24
29
  static (path = "public", option) {
25
- var serve = option || this.serve;
26
- this.express.use ($.express.static (path, serve));
30
+ this.express.use ($.express.static (path, (option || this.config.static)));
27
31
  return this;
28
32
  }
29
- setup (context) {
33
+ setup (setup) {
30
34
  var io = function (app) {
31
- return function (r, respond, next) {
35
+ return async function (r, respond, next) {
32
36
  var http_d = {request: r, response: respond}
33
37
  var {request, response} = express.io (app, http_d);
34
38
  app.__ = {request, response}
35
- express.setup (app.__.request, app.__.response, next, http_d);
36
- context (app.__.request, app.__.response, next, http_d);
39
+ await new Promise (function (resolve, reject) { express.setup.call (app, app.__.request, app.__.response, resolve); });
40
+ await new Promise (function (resolve, reject) { setup.call (app, app.__.request, app.__.response, resolve); });
41
+ express.security.call (app, app.__.request, app.__.response, next);
37
42
  }
38
43
  }
39
44
  this.express.use (io (this));
@@ -41,12 +46,7 @@ class express {
41
46
  }
42
47
  io (app, context) {
43
48
  return function (request, response, next) {
44
- if (app.__.request.error.length) {
45
- if (app.__.request.error.includes ("forbidden")) app.__.response.error.forbidden ();
46
- else if (app.__.request.error.includes ("found")) app.__.response.error.found ();
47
- else app.__.response.error ();
48
- }
49
- else context (app.__.request, app.__.response, next, {request, response});
49
+ context (app.__.request, app.__.response, next, {request, response});
50
50
  }
51
51
  }
52
52
  use (... context) {
@@ -88,34 +88,64 @@ express.io = function (app, http_d) {
88
88
  }
89
89
 
90
90
  express.request = function (app, http_d) {
91
- var request = function () {}
91
+ const request = function () {}
92
92
  request.error = [];
93
93
  request.header = http_d.request.headers;
94
94
  if (request.url = function () {}) {
95
- var protocol = http_d.request.protocol || "http";
95
+ var protocol = request.header ["x-forwarded-proto"] || http_d.request.protocol || "http";
96
96
  if (app.config.internet) protocol = "https";
97
97
  request.base_url = `${protocol}://${http_d.request.host}`;
98
98
  var parse_url = URL.parse (request.url.address = `${request.base_url}${http_d.request.url}`);
99
99
  for (var i in parse_url) request.url [i] = parse_url [i];
100
+ request.get = function (... arg) {
101
+ return http_d.request.get (... arg);
102
+ }
100
103
  }
101
- request.get = function (... get) {
102
- return http_d.request.get (... get);
104
+ if (request.visitor = {}) {
105
+ var ip_address = request.header ["x-real-ip"] || "127.0.0.1";
106
+ var country_code = request.header ["x-vercel-ip-country"] || "";
107
+ var country_name = "";
108
+ var country_region = request.header ["x-vercel-ip-country-region"] || "";
109
+ var country_city_code = "";
110
+ var country_city_name = request.header ["x-vercel-ip-city"] || "";
111
+ var country_timezone = request.header ["x-vercel-ip-timezone"] || "";
112
+ var coordinate_latitude = request.header ["x-vercel-ip-latitude"] || "";
113
+ var coordinate_longitude = request.header ["x-vercel-ip-longitude"] || "";
114
+ request.visitor.ip = {address: ip_address}
115
+ request.visitor.country = {code: country_code, name: country_name, region: country_region, city: {name: country_city_name}, timezone: country_timezone, coordinate: {latitude: coordinate_latitude, longitude: coordinate_longitude}}
116
+ request.visitor.browser = request.header ["user-agent"];
103
117
  }
118
+ request.db = function () {}
119
+ request.j_son = function () {}
120
+ request.theme = function () {}
104
121
  return request;
105
122
  }
106
123
 
107
124
  express.response = function (app, request, http_d) {
108
125
  var response = function () {}
109
- response.status = function (code) { http_d.response.status (code); return response; }
110
- response.json = function (... context) { http_d.response.json (... context); return response; }
111
- response.html = function (... context) {
112
- http_d.response.send (... context);
113
- return response;
114
- }
115
- response.output = new $.html ();
116
- response.error = function (code = 500) { http_d.response.status (code).send (URL.header.status.code [code]); }
117
- response.error.forbidden = function (code = 403) { http_d.response.status (code).send (URL.header.status.code [code]); }
118
- response.error.found = function (code = 404) { http_d.response.status (code).send (URL.header.status.code [code]); }
126
+ if ("output") {
127
+ response.var = $.object.create (null);
128
+ response.output = new $.html ();
129
+ response.status = function (code) { http_d.response.status (code); return response; }
130
+ response.text = function () {}
131
+ response.css = function () {}
132
+ response.js = function () {}
133
+ response.xml = function () {}
134
+ response.json = function (... context) { http_d.response.json (... context); return response; }
135
+ response.html = function (... context) {
136
+ http_d.response.send (... context);
137
+ return response;
138
+ }
139
+ response.render = function () {}
140
+ }
141
+ if ("error") {
142
+ response.error = function (code = 500) { http_d.response.status (code).send (response.error.message || URL.header.status.code [code]); return response; }
143
+ response.error.forbidden = function (code = 403) { http_d.response.status (code).send (URL.header.status.code [code]); return response; }
144
+ response.error.found = function (code = 404) { http_d.response.status (code).send (URL.header.status.code [code]); return response; }
145
+ }
146
+ if ("db") {
147
+ response.db = function () {}
148
+ }
119
149
  return response;
120
150
  }
121
151
 
@@ -129,15 +159,36 @@ express.response = function (app, request, http_d) {
129
159
  * xxx://xxx.xxx.xxx/xxx
130
160
  */
131
161
 
132
- express.setup = function (request, response, next, http_d) {
162
+ express.setup = async function (request, response, next) {
163
+ if ("db") {
164
+ if (this.config.db.driver === "json") {
165
+ request.db = new JSON.db ({dir: this.dir.db, collection: this.config.db.collection});
166
+ }
167
+ }
168
+ if ("app:client") {
169
+ request.app = (await request.db.select ("app").find ({host: request.url.host.name})).data.one ()
170
+ }
133
171
  if (true) {
134
172
  response.output.set ("language", "en");
135
173
  response.output.set ("html:attribute", {translate: "no", prefix: "og: http://ogp.me/ns#"});
136
174
  response.output.set ("canonical", request.url.address);
137
175
  response.output.set ("favorite.ico", request.base_url.join ("/favicon.ico"));
138
176
  response.output.set ("debug", JSON.pretty (request.header));
139
- if (false) response.output.set ("meta", {attribute: {name: "adsterra", content: "ads"}});
177
+ if (false) response.output.set ("meta", {attribute: {name: "key", content: "value"}});
178
+ }
179
+ this.emit ("setup", request, response);
180
+ this.emit ("j_son:setup", request, response);
181
+ next ();
182
+ }
183
+
184
+ express.security = function (request, response, next) {
185
+ this.emit ("security", request, response);
186
+ if (request.error.length) {
187
+ if (request.error.includes ("forbidden")) response.error.forbidden ();
188
+ else if (request.error.includes ("found")) response.error.found ();
189
+ else response.error ();
140
190
  }
191
+ next ();
141
192
  }
142
193
 
143
194
  /**
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.1248",
4
+ "version": "1.022.1015",
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.1248"
25
+ "script.io.js": "^1.022.1015"
26
26
  }
27
27
  }