express.io.js 1.0.1611 → 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.
- package/node_packages/express.js +75 -37
- package/package.json +2 -2
package/node_packages/express.js
CHANGED
|
@@ -16,26 +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.
|
|
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")
|
|
23
27
|
Event.proto (this);
|
|
24
28
|
}
|
|
25
29
|
static (path = "public", option) {
|
|
26
|
-
|
|
27
|
-
this.express.use ($.express.static (path, serve));
|
|
30
|
+
this.express.use ($.express.static (path, (option || this.config.static)));
|
|
28
31
|
return this;
|
|
29
32
|
}
|
|
30
|
-
setup (
|
|
33
|
+
setup (setup) {
|
|
31
34
|
var io = function (app) {
|
|
32
35
|
return async function (r, respond, next) {
|
|
33
36
|
var http_d = {request: r, response: respond}
|
|
34
37
|
var {request, response} = express.io (app, http_d);
|
|
35
38
|
app.__ = {request, response}
|
|
36
|
-
await express.setup.call (app, app.__.request, app.__.response);
|
|
37
|
-
|
|
38
|
-
|
|
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);
|
|
39
42
|
}
|
|
40
43
|
}
|
|
41
44
|
this.express.use (io (this));
|
|
@@ -85,38 +88,64 @@ express.io = function (app, http_d) {
|
|
|
85
88
|
}
|
|
86
89
|
|
|
87
90
|
express.request = function (app, http_d) {
|
|
88
|
-
|
|
91
|
+
const request = function () {}
|
|
89
92
|
request.error = [];
|
|
90
93
|
request.header = http_d.request.headers;
|
|
91
94
|
if (request.url = function () {}) {
|
|
92
|
-
var protocol = http_d.request.protocol || "http";
|
|
95
|
+
var protocol = request.header ["x-forwarded-proto"] || http_d.request.protocol || "http";
|
|
93
96
|
if (app.config.internet) protocol = "https";
|
|
94
97
|
request.base_url = `${protocol}://${http_d.request.host}`;
|
|
95
98
|
var parse_url = URL.parse (request.url.address = `${request.base_url}${http_d.request.url}`);
|
|
96
99
|
for (var i in parse_url) request.url [i] = parse_url [i];
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
+
request.get = function (... arg) {
|
|
101
|
+
return http_d.request.get (... arg);
|
|
102
|
+
}
|
|
100
103
|
}
|
|
101
104
|
if (request.visitor = {}) {
|
|
102
|
-
request.
|
|
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}}
|
|
103
116
|
request.visitor.browser = request.header ["user-agent"];
|
|
104
117
|
}
|
|
118
|
+
request.db = function () {}
|
|
119
|
+
request.j_son = function () {}
|
|
120
|
+
request.theme = function () {}
|
|
105
121
|
return request;
|
|
106
122
|
}
|
|
107
123
|
|
|
108
124
|
express.response = function (app, request, http_d) {
|
|
109
125
|
var response = function () {}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
http_d.response.
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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
|
+
}
|
|
120
149
|
return response;
|
|
121
150
|
}
|
|
122
151
|
|
|
@@ -130,27 +159,36 @@ express.response = function (app, request, http_d) {
|
|
|
130
159
|
* xxx://xxx.xxx.xxx/xxx
|
|
131
160
|
*/
|
|
132
161
|
|
|
133
|
-
express.
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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 ()
|
|
139
170
|
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
express.setup = function (request, response) {
|
|
143
171
|
if (true) {
|
|
144
172
|
response.output.set ("language", "en");
|
|
145
173
|
response.output.set ("html:attribute", {translate: "no", prefix: "og: http://ogp.me/ns#"});
|
|
146
174
|
response.output.set ("canonical", request.url.address);
|
|
147
175
|
response.output.set ("favorite.ico", request.base_url.join ("/favicon.ico"));
|
|
148
176
|
response.output.set ("debug", JSON.pretty (request.header));
|
|
149
|
-
if (false) response.output.set ("meta", {attribute: {name: "
|
|
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 ();
|
|
150
190
|
}
|
|
151
|
-
|
|
152
|
-
resolve (true);
|
|
153
|
-
});
|
|
191
|
+
next ();
|
|
154
192
|
}
|
|
155
193
|
|
|
156
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.
|
|
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.
|
|
25
|
+
"script.io.js": "^1.022.1015"
|
|
26
26
|
}
|
|
27
27
|
}
|