jsgui3-server 0.0.82 → 0.0.85
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/README.md +8 -1
- package/bundler/bundle.js +11 -0
- package/bundler/bundler.js +9 -0
- package/bundler/css-bundler.js +56 -0
- package/bundler/js-bundler.js +214 -0
- package/bundler/test_ast.js +74 -0
- package/bundler/webpage-bundler.js +286 -0
- package/bundler/website-bundler.js +23 -0
- package/controls/README.md +8 -0
- package/controls/page/admin.js +75 -0
- package/controls/panel/admin.js +11 -0
- package/examples/controls/html-server-combo-box.js +5 -5
- package/examples/html-server.js +3 -0
- package/examples/square_box.js +41 -0
- package/examples/square_box_client.js +91 -0
- package/module.js +6 -0
- package/{single-control-server.js → old/_single-control-server.js} +157 -96
- package/old/single-control-server.js +108 -158
- package/{single-page-app.js → old/single-page-app.js} +2 -0
- package/{examples/demos → old}/square_box.js +1 -1
- package/package.json +9 -9
- package/page-context.js +1 -1
- package/publishing/http-css-publisher.js +0 -0
- package/publishing/{function-publisher.js → http-function-publisher.js} +11 -1
- package/publishing/http-html-page-publisher.js +5 -0
- package/publishing/http-html-publisher.js +25 -0
- package/publishing/http-jpeg-publisher.js +0 -0
- package/publishing/http-js-publisher.js +25 -0
- package/publishing/{observable-publisher.js → http-observable-publisher.js} +12 -6
- package/publishing/http-png-publisher.js +0 -0
- package/publishing/http-publisher.js +52 -0
- package/publishing/{resource-publisher.js → http-resource-publisher.js} +20 -1
- package/publishing/http-svg-publisher.js +0 -0
- package/publishing/http-webpage-publisher.js +112 -0
- package/publishing/http-website-publisher.js +271 -0
- package/publishing/notes.md +1 -0
- package/resources/README.md +16 -0
- package/resources/_old_website-resource.js +507 -0
- package/resources/compile/server-resource-compilation.js +41 -0
- package/resources/data-resource.js +8 -0
- package/resources/fs-resource.js +2 -4
- package/resources/jsbuilder/babel/deep_iterate/deep_iterate_babel.js +3 -0
- package/resources/jsbuilder/test/test_ast_node.js +1 -1
- package/resources/jsbuilder/test/test_js_file.js +2 -2
- package/resources/notes.txt +11 -0
- package/resources/server-installed-tools.js +29 -0
- package/resources/server-resource-pool.js +1 -55
- package/resources/website-css-resource.js +1 -1
- package/resources/website-javascript-resource.js +165 -34
- package/resources/website-resource.js +52 -296
- package/resources/website-static-html-resource.js +0 -1
- package/resources/website-template-html-resource.js +231 -0
- package/roadmap.md +68 -0
- package/server.js +722 -17
- package/website/webpage.js +169 -0
- package/website/website-group.js +16 -0
- package/website/website.js +253 -0
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
* Created by James on 29/07/2014.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
+
// 2022 - Seems a little uncertain about what it is for, and what it does has grown over time.
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
// A Website abstraction and a Website_Publisher seem like a good way forward.
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
// Want to make a near future release have a web publishing system that is easier to use as well as more
|
|
13
|
+
// powerful.
|
|
14
|
+
|
|
15
|
+
// Publishing static sites, rendering and compiling.
|
|
16
|
+
|
|
5
17
|
// Represents (and is?) a website itself, and its representation available through the Resource system.
|
|
6
18
|
|
|
7
19
|
|
|
@@ -49,6 +61,17 @@
|
|
|
49
61
|
// It would be much more secure to bring up an NTP provision service automatically than a file system one. Don't want to take that risk now.
|
|
50
62
|
//
|
|
51
63
|
|
|
64
|
+
// Possibly WebPack could be considered such a resource? Or find a different type for that type of resource?
|
|
65
|
+
|
|
66
|
+
// Compilation_Resource and Compiler_Resource...
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
// Maybe should do more to represent a website on a server.
|
|
70
|
+
// Maybe it needs more docs, being rather critical.
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
52
75
|
var Site_Images = require("./website-image-resource");
|
|
53
76
|
|
|
54
77
|
//console.log('1) Site_Images', Site_Images);
|
|
@@ -61,19 +84,19 @@ const Resource = jsgui.Resource;
|
|
|
61
84
|
const Router = jsgui.Router;
|
|
62
85
|
//const Evented_Class = jsgui.Evented_Class;
|
|
63
86
|
|
|
64
|
-
|
|
87
|
+
const Resource_Pool = require("./server-resource-pool");
|
|
65
88
|
//var Resource_Web_Admin = require('../web-admin');
|
|
66
89
|
|
|
67
|
-
|
|
90
|
+
const Site_JavaScript = require("./website-javascript-resource");
|
|
68
91
|
//console.log('1) Site_JavaScript', Site_JavaScript);
|
|
69
|
-
|
|
70
|
-
|
|
92
|
+
const Site_CSS = require("./website-css-resource");
|
|
93
|
+
const Site_Static_HTML = require("./website-static-html-resource");
|
|
71
94
|
//var DB_Web_Resource = require('../../web/db-resource-postgres');
|
|
72
95
|
//var database_resource_factory = require('../../db/resource/factory');
|
|
73
96
|
|
|
74
|
-
const Resource_Publisher = require("../publishing/resource-publisher");
|
|
75
|
-
const Observable_Publisher = require("../publishing/observable-publisher");
|
|
76
|
-
const Function_Publisher = require("../publishing/function-publisher");
|
|
97
|
+
const Resource_Publisher = require("../publishing/http-resource-publisher");
|
|
98
|
+
const Observable_Publisher = require("../publishing/http-observable-publisher");
|
|
99
|
+
const Function_Publisher = require("../publishing/http-function-publisher");
|
|
77
100
|
//const Data_Resource = require("./data-resource");
|
|
78
101
|
|
|
79
102
|
// Proxy_Server_Resource possibly.
|
|
@@ -84,279 +107,43 @@ const Function_Publisher = require("../publishing/function-publisher");
|
|
|
84
107
|
|
|
85
108
|
// May help with FirstPoint_Server.
|
|
86
109
|
|
|
110
|
+
// Could move the publishing parts to Website_Resource_Publisher perhaps.
|
|
87
111
|
|
|
88
112
|
|
|
89
113
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
super(spec);
|
|
93
|
-
// A bit of a special resource here because it has its own resource_pool.
|
|
94
|
-
var resource_pool = new Resource_Pool({
|
|
95
|
-
name: "Website Resource Pool"
|
|
96
|
-
});
|
|
97
|
-
this.resource_pool = resource_pool;
|
|
98
|
-
var database_spec = spec.database;
|
|
99
|
-
var web_database_resource;
|
|
100
|
-
|
|
101
|
-
if (database_spec) {
|
|
102
|
-
database_spec.name = database_spec.name || database_spec.database_name;
|
|
103
|
-
var database_resource = database_resource_factory(database_spec);
|
|
104
|
-
database_resource.start();
|
|
105
|
-
// should start automatically when in the pool?
|
|
106
|
-
// does the pool need to be told to start?
|
|
107
|
-
// Though probably don't want to start the resource on initialization.
|
|
108
|
-
resource_pool.add(database_resource);
|
|
109
|
-
web_database_resource = new DB_Web_Resource({
|
|
110
|
-
database: database_resource,
|
|
111
|
-
meta: {
|
|
112
|
-
name: "Web DB",
|
|
113
|
-
pool: resource_pool
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (web_database_resource) {
|
|
119
|
-
resource_pool.add(web_database_resource);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
var router = new Router({
|
|
123
|
-
name: "Site Router"
|
|
124
|
-
});
|
|
114
|
+
// Maybe worth just having a Website object.
|
|
115
|
+
// Then the Website_Resource can encapsulate that.
|
|
125
116
|
|
|
126
|
-
|
|
117
|
+
// Better if this wraps the Website object?
|
|
127
118
|
|
|
128
|
-
|
|
129
|
-
//'web_database': web_database_resource,
|
|
130
|
-
meta: {
|
|
131
|
-
name: "Web Admin"
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
//if (web_database_resource) {
|
|
136
|
-
// spec_web_admin.web_database = web_database_resource;
|
|
137
|
-
//}
|
|
138
|
-
|
|
139
|
-
var img_resource = new Site_Images({
|
|
140
|
-
//'meta': {
|
|
141
|
-
name: "Site Images",
|
|
142
|
-
pool: resource_pool
|
|
143
|
-
// }
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
var js_resource = new Site_JavaScript({
|
|
147
|
-
//'meta': {
|
|
148
|
-
name: "Site JavaScript",
|
|
149
|
-
pool: resource_pool
|
|
150
|
-
//}
|
|
151
|
-
});
|
|
119
|
+
// A Website has its own Website Resource Pool?
|
|
152
120
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
// Probably with the static or simplest settings.
|
|
156
|
-
|
|
157
|
-
var static_html_resource;
|
|
158
|
-
|
|
159
|
-
if (spec == "static") {
|
|
160
|
-
static_html_resource = new Site_Static_HTML({
|
|
161
|
-
//'meta': {
|
|
162
|
-
name: "Static HTML",
|
|
163
|
-
pool: resource_pool
|
|
164
|
-
//}
|
|
165
|
-
});
|
|
166
|
-
resource_pool.push(static_html_resource);
|
|
167
|
-
// Perhaps set it up with the specific files (automatically)?
|
|
168
|
-
// Probably with the index.html
|
|
169
|
-
}
|
|
170
|
-
var css_resource = new Site_CSS({
|
|
171
|
-
//'meta': {
|
|
172
|
-
name: "Site CSS",
|
|
173
|
-
pool: resource_pool
|
|
174
|
-
//}
|
|
175
|
-
});
|
|
121
|
+
// Make Website_Resource into the wrapper that wraps Website?
|
|
122
|
+
// Or we don't need that, just use HTTP_Website_Publisher.
|
|
176
123
|
|
|
124
|
+
// Maybe this won't be necessary in various cases.
|
|
177
125
|
|
|
178
|
-
|
|
179
|
-
css_resource.serve_str_css('controls.css', str_extracted_css);
|
|
180
|
-
// Will serve this as controls.css
|
|
181
|
-
// Separate HTTP request, will get more CSS for the moment.
|
|
126
|
+
// For the moment won't make this website resource do all that much.
|
|
182
127
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
resource_pool.
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
// Routing maybe wouldn't work like that.
|
|
193
|
-
//router.set_route('*.css', css_resource, css_resource.process);
|
|
194
|
-
|
|
195
|
-
router.set_route("css/*", css_resource, css_resource.process);
|
|
196
|
-
router.set_route("js/*", js_resource, js_resource.process);
|
|
197
|
-
// As well as this, it could get the JavaScript resource to serve the JavaScript from the app's js directory.
|
|
198
|
-
js_resource.serve_directory("js");
|
|
199
|
-
router.set_route("i/*", img_resource, img_resource.process);
|
|
200
|
-
router.set_route("img/*", img_resource, img_resource.process);
|
|
201
|
-
router.set_route("imgs/*", img_resource, img_resource.process);
|
|
202
|
-
router.set_route("images/*", img_resource, img_resource.process);
|
|
203
|
-
this.map_resource_publishers = this.map_resource_publishers || {};
|
|
204
|
-
router.set_route("resources/:resource_name/*", this, (req, res) => {
|
|
205
|
-
let { url, method } = req;
|
|
206
|
-
let s_url = url.split("/");
|
|
207
|
-
let resource_short_name = s_url[2];
|
|
208
|
-
let resource_publisher = this.map_resource_publishers[resource_short_name];
|
|
209
|
-
if (resource_publisher) {
|
|
210
|
-
resource_publisher.handle_http(req, res);
|
|
128
|
+
class Website_Resource extends Resource {
|
|
129
|
+
constructor(spec = {}) {
|
|
130
|
+
super(spec);
|
|
131
|
+
// A bit of a special resource here because it has its own resource_pool.
|
|
132
|
+
let website;
|
|
133
|
+
if (spec.website) website = spec.website;
|
|
134
|
+
Object.defineProperty(this, 'website', {
|
|
135
|
+
get() {
|
|
136
|
+
return website;
|
|
211
137
|
}
|
|
212
138
|
});
|
|
213
|
-
if (!is_defined(spec)) spec = {};
|
|
214
|
-
this.resource_pool = resource_pool;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
publishing_get_pub(item) {
|
|
218
|
-
let pub;
|
|
219
|
-
if (item instanceof jsgui.Resource) {
|
|
220
|
-
pub = new Resource_Publisher({
|
|
221
|
-
resource: item
|
|
222
|
-
});
|
|
223
|
-
} else {
|
|
224
|
-
// if its a function
|
|
225
|
-
// return that function call to the response.
|
|
226
|
-
let t_item = typeof item;
|
|
227
|
-
if (t_item === "function") {
|
|
228
|
-
// Function_Call_Publisher
|
|
229
|
-
// could respec this.
|
|
230
|
-
// And the Function_Publisher operates through the Publisher API. Not sure what that is right now though.
|
|
231
|
-
|
|
232
|
-
pub = new Function_Publisher({
|
|
233
|
-
fn: item
|
|
234
|
-
});
|
|
235
|
-
//this.map_resource_publishers[published_name] = pub;
|
|
236
|
-
//
|
|
237
|
-
} else {
|
|
238
|
-
if (item.next && item.complete && item.error) {
|
|
239
|
-
// assuming observable
|
|
240
|
-
// Observable publisher
|
|
241
|
-
// One way sending...
|
|
242
|
-
//console.log('using Observable_Publisher');
|
|
243
|
-
pub = new Observable_Publisher({
|
|
244
|
-
obs: item
|
|
245
|
-
});
|
|
246
|
-
// or not a resource publisher, an observable publisher.
|
|
247
|
-
//this.map_resource_publishers = this.map_resource_publishers || {};
|
|
248
|
-
//this.map_resource_publishers[published_name] = obs_pub;
|
|
249
|
-
|
|
250
|
-
//console.log('2) this', this);
|
|
251
|
-
//console.log('this.map_resource_publishers', this.map_resource_publishers);
|
|
252
|
-
//console.trace();
|
|
253
|
-
} else {
|
|
254
|
-
console.log("item", item);
|
|
255
|
-
throw "Unrecognised item type. Possibly node module versions are wrong / have not been linked fully.";
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
//if (item instanceof Evented_Class) {
|
|
259
|
-
}
|
|
260
|
-
return pub;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
// publish within resources?
|
|
264
|
-
publish(published_name, item, schema) {
|
|
265
|
-
let sig = get_a_sig(arguments),
|
|
266
|
-
a = arguments,
|
|
267
|
-
l = a.length;
|
|
268
|
-
const single = (published_name, item) => {
|
|
269
|
-
if (item instanceof jsgui.Resource) {
|
|
270
|
-
let resource_publisher = new Resource_Publisher({
|
|
271
|
-
resource: item,
|
|
272
|
-
name: published_name
|
|
273
|
-
});
|
|
274
|
-
this.map_resource_publishers[published_name] = resource_publisher;
|
|
275
|
-
|
|
276
|
-
item.name = item.name || published_name;
|
|
277
|
-
// add that resource!
|
|
278
|
-
// (to the pool?)
|
|
279
|
-
//console.log('item', item);
|
|
280
|
-
this.resource_pool.add(item);
|
|
281
|
-
|
|
282
|
-
//console.log('Object.keys(this.map_resource_publishers)', Object.keys(this.map_resource_publishers));
|
|
283
|
-
} else {
|
|
284
|
-
// if its a function
|
|
285
|
-
// return that function call to the response.
|
|
286
|
-
let t_item = typeof item;
|
|
287
|
-
if (t_item === "function") {
|
|
288
|
-
// Function_Call_Publisher
|
|
289
|
-
// could respec this.
|
|
290
|
-
|
|
291
|
-
// And the Function_Publisher operates through the Publisher API. Not sure what that is right now though.
|
|
292
|
-
// directly attaching the resource publishers?
|
|
293
|
-
let pub = new Function_Publisher({
|
|
294
|
-
fn: item,
|
|
295
|
-
schema: schema
|
|
296
|
-
});
|
|
297
|
-
this.map_resource_publishers[published_name] = pub;
|
|
298
|
-
//
|
|
299
|
-
|
|
300
|
-
} else {
|
|
301
|
-
if (item.next && item.complete && item.error) {
|
|
302
|
-
let obs_pub = new Observable_Publisher({
|
|
303
|
-
obs: item,
|
|
304
|
-
schema: schema
|
|
305
|
-
});
|
|
306
|
-
this.map_resource_publishers[published_name] = obs_pub;
|
|
307
|
-
} else {
|
|
308
|
-
console.log("item", item);
|
|
309
|
-
throw "Unrecognised item type. Possibly node module versions are wrong / have not been linked fully.";
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
//if (item instanceof Evented_Class) {
|
|
313
|
-
}
|
|
314
|
-
};
|
|
315
|
-
|
|
316
|
-
if (sig === "[o]") {
|
|
317
|
-
each(a[0], (v, i) => {
|
|
318
|
-
single(i, v);
|
|
319
|
-
})
|
|
320
|
-
} else {
|
|
321
139
|
|
|
322
|
-
single(published_name, item);
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
get resource_names() {
|
|
327
|
-
//console.log('this.resource_pool', this.resource_pool);
|
|
328
|
-
return this.resource_pool.resource_names;
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
get_resource(resource_name) {
|
|
332
|
-
var resource_pool = this.resource_pool;
|
|
333
|
-
//console.log('resource_pool', resource_pool);
|
|
334
|
-
|
|
335
|
-
//console.log('this._.resource_pool', this._.resource_pool);
|
|
336
|
-
|
|
337
|
-
//throw 'stop';
|
|
338
|
-
return resource_pool.get_resource(resource_name);
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
get def_resource_publishers() {
|
|
342
|
-
const res = {};
|
|
343
|
-
each(this.map_resource_publishers, (rp, name) => {
|
|
344
|
-
|
|
345
|
-
let def = {
|
|
346
|
-
name: name,
|
|
347
|
-
type: rp.type
|
|
348
|
-
}
|
|
349
|
-
res[name] = def;
|
|
350
|
-
if (rp.type === 'function') {
|
|
351
|
-
if (rp.schema) def.schema = rp.schema;
|
|
352
|
-
}
|
|
353
|
-
});
|
|
354
|
-
return res;
|
|
355
140
|
}
|
|
356
141
|
|
|
357
142
|
start(callback) {
|
|
358
|
-
var resource_pool = this.resource_pool;
|
|
359
|
-
resource_pool.start(callback);
|
|
143
|
+
//var resource_pool = this.resource_pool;
|
|
144
|
+
//resource_pool.start(callback);
|
|
145
|
+
|
|
146
|
+
callback(null, true);
|
|
360
147
|
}
|
|
361
148
|
|
|
362
149
|
meets_requirements() {
|
|
@@ -366,37 +153,6 @@ class Website_Resource extends Resource {
|
|
|
366
153
|
|
|
367
154
|
return true;
|
|
368
155
|
}
|
|
369
|
-
|
|
370
|
-
// Needs to be able to process HTTP requests. A bit like the Router in that way.
|
|
371
|
-
process(req, res) {
|
|
372
|
-
//console.log('website process request req.url', req.url);
|
|
373
|
-
//throw 'stop';
|
|
374
|
-
|
|
375
|
-
var remoteAddress = req.connection.remoteAddress;
|
|
376
|
-
var router = this.router;
|
|
377
|
-
var res_process = router.process(req, res);
|
|
378
|
-
if (res_process === false) {
|
|
379
|
-
if (req.url === "/") {
|
|
380
|
-
// Send this to the static HTML processing system.
|
|
381
|
-
|
|
382
|
-
var static_html_resource = this.resource_pool.get_resource(
|
|
383
|
-
"Static HTML"
|
|
384
|
-
);
|
|
385
|
-
//console.log('static_html_resource', static_html_resource);
|
|
386
|
-
// And lets get the static resource to process it
|
|
387
|
-
if (static_html_resource) {
|
|
388
|
-
static_html_resource.process(req, res);
|
|
389
|
-
}
|
|
390
|
-
} else {
|
|
391
|
-
// show a 404
|
|
392
|
-
res.writeHead(404, {
|
|
393
|
-
"Content-Type": "text/plain"
|
|
394
|
-
});
|
|
395
|
-
res.write("404 Not Found\n");
|
|
396
|
-
res.end();
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
156
|
}
|
|
401
157
|
|
|
402
158
|
module.exports = Website_Resource;
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
var path = require('path'), fs = require('fs'),
|
|
2
|
+
url = require('url'), jsgui = require('jsgui3-html'), os = require('os'), http = require('http'), libUrl = require('url'),
|
|
3
|
+
Resource = jsgui.Resource,
|
|
4
|
+
Cookies = require('cookies'), fs2 = require('../fs2');
|
|
5
|
+
|
|
6
|
+
var stringify = jsgui.stringify, each = jsgui.each, arrayify = jsgui.arrayify, tof = jsgui.tof;
|
|
7
|
+
var filter_map_by_regex = jsgui.filter_map_by_regex;
|
|
8
|
+
var Class = jsgui.Class, Data_Object = jsgui.Data_Object, Enhanced_Data_Object = jsgui.Enhanced_Data_Object;
|
|
9
|
+
var fp = jsgui.fp, is_defined = jsgui.is_defined;
|
|
10
|
+
var Collection = jsgui.Collection;
|
|
11
|
+
|
|
12
|
+
// Extends AutoStart_Resource?
|
|
13
|
+
// May need to change around a fair few references to make it workable.
|
|
14
|
+
// May need some more complicated logic to change it to the path for service.
|
|
15
|
+
|
|
16
|
+
// Maybe this will be / need a Compiler.
|
|
17
|
+
|
|
18
|
+
// website-html-resource....
|
|
19
|
+
// may be useful to have / use a Resource for the HTML servinh=g / compilation.
|
|
20
|
+
|
|
21
|
+
// Consider the server as an HTML compiler? Or a more complex compiler?
|
|
22
|
+
|
|
23
|
+
// Seems more like loading server-side compilers is the way.
|
|
24
|
+
// Load them into jsgui.
|
|
25
|
+
|
|
26
|
+
// lang.load_compiler
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
var serve_fn_html_template_from_disk = function(filePath, fn_template, obj_data, response) {
|
|
35
|
+
|
|
36
|
+
// serve templated file as html...
|
|
37
|
+
|
|
38
|
+
fs2.load_file_as_string(filePath, function (err, data) {
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
if (err) {
|
|
42
|
+
throw err;
|
|
43
|
+
} else {
|
|
44
|
+
const templated = fn_template(data, obj_data);
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
//var servableJs = updateReferencesForServing(data);
|
|
50
|
+
response.writeHead(200, {'Content-Type': 'text/html'});
|
|
51
|
+
response.end(templated);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
// File_Server_Resource?
|
|
58
|
+
// So the resource has code to route to the file and then serve it.
|
|
59
|
+
|
|
60
|
+
// Also a Templated_HTML resource?
|
|
61
|
+
// Connects to HTML_Template
|
|
62
|
+
// Connects to Data_Resource
|
|
63
|
+
// Populates the HTML_Template data from the Data_Resource
|
|
64
|
+
|
|
65
|
+
// HTML_Template being a Data_Transformation / Data_Transformation_Resource / Transformation_Resource
|
|
66
|
+
// Codecs could be another type of Transformation_Resource
|
|
67
|
+
|
|
68
|
+
// Transformation Resource could / should appear in jsgui3-client. Makes sense on the client too.
|
|
69
|
+
|
|
70
|
+
// Separate loading of transformation resource, data resource, and template (resource)
|
|
71
|
+
// The transformation resource can itself load / be provided with the data resource and template resource.
|
|
72
|
+
|
|
73
|
+
// jsx processing may be the best way (by far)?
|
|
74
|
+
|
|
75
|
+
// or jsui templates?
|
|
76
|
+
// jsx may seem / be easiest at this stage for long term expansion and integration.
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class Site_Template_HTML extends Resource {
|
|
81
|
+
|
|
82
|
+
constructor(spec) {
|
|
83
|
+
super(spec);
|
|
84
|
+
|
|
85
|
+
this.meta.set('custom_paths', new Data_Object({}));
|
|
86
|
+
// Those are custom file paths.
|
|
87
|
+
|
|
88
|
+
// could have a collection of directories, indexed by name, that get served.
|
|
89
|
+
|
|
90
|
+
// Index the collection by string value?
|
|
91
|
+
this.meta.set('served_directories', new Collection({'index_by': 'name'}));
|
|
92
|
+
}
|
|
93
|
+
'start'(callback) {
|
|
94
|
+
callback(null, true);
|
|
95
|
+
}
|
|
96
|
+
'set_custom_path'(url, file_path) {
|
|
97
|
+
// But change the URL to have a smiley face instead of fullstops
|
|
98
|
+
//console.log('url', url);
|
|
99
|
+
var escaped_url = url.replace(/\./g, '☺');
|
|
100
|
+
//console.log('escaped_url', escaped_url);
|
|
101
|
+
|
|
102
|
+
//this.meta.set('custom_paths.' + escaped_url, file_path);
|
|
103
|
+
var custom_paths = this.meta.get('custom_paths');
|
|
104
|
+
//console.log('custom_paths', custom_paths);
|
|
105
|
+
custom_paths.set(escaped_url, file_path);
|
|
106
|
+
|
|
107
|
+
}
|
|
108
|
+
'serve_directory'(path) {
|
|
109
|
+
// Serves that directory, as any files given in that directory can be served from /js
|
|
110
|
+
var served_directories = this.meta.get('served_directories');
|
|
111
|
+
//console.log('served_directories ' + stringify(served_directories));
|
|
112
|
+
//served_directories.push(path);
|
|
113
|
+
served_directories.push({
|
|
114
|
+
'name': path
|
|
115
|
+
});
|
|
116
|
+
//console.log('served_directories ' + stringify(served_directories));
|
|
117
|
+
//console.log('path ' + path);
|
|
118
|
+
|
|
119
|
+
//throw 'stop';
|
|
120
|
+
|
|
121
|
+
}
|
|
122
|
+
'process'(req, res) {
|
|
123
|
+
//console.log('Site_Static_HTML processing');
|
|
124
|
+
var remoteAddress = req.connection.remoteAddress;
|
|
125
|
+
var custom_paths = this.custom_paths;
|
|
126
|
+
var rurl = req.url;
|
|
127
|
+
var pool = this.pool;
|
|
128
|
+
// should have a bunch of resources from the pool.
|
|
129
|
+
//var pool_resources = pool.resources();
|
|
130
|
+
//console.log('pool_resources ' + stringify(pool_resources));
|
|
131
|
+
|
|
132
|
+
var url_parts = url.parse(req.url, true);
|
|
133
|
+
//console.log('url_parts ' + stringify(url_parts));
|
|
134
|
+
var splitPath = url_parts.path.substr(1).split('/');
|
|
135
|
+
//console.log('resource site css splitPath ' + stringify(splitPath));
|
|
136
|
+
|
|
137
|
+
if (rurl.substr(0, 1) == '/') rurl = rurl.substr(1);
|
|
138
|
+
rurl = rurl.replace(/\./g, '☺');
|
|
139
|
+
//console.log('rurl ' + rurl);
|
|
140
|
+
|
|
141
|
+
if (rurl == '') rurl = '/';
|
|
142
|
+
var custom_response_entry = custom_paths.get(rurl);
|
|
143
|
+
//console.log('Static HTML Resource process url', req.url);
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
//console.log('custom_response_entry ' + stringify(custom_response_entry));
|
|
147
|
+
|
|
148
|
+
if (custom_response_entry) {
|
|
149
|
+
var tcr = tof(custom_response_entry);
|
|
150
|
+
//console.log('tcr ' + tcr);
|
|
151
|
+
if (tcr == 'data_value') {
|
|
152
|
+
var val = custom_response_entry.value();
|
|
153
|
+
//console.log('val ' + val);
|
|
154
|
+
var tval = tof(val);
|
|
155
|
+
if (tval === 'string') {
|
|
156
|
+
// then it should be a local file path, serve it.
|
|
157
|
+
// need to specify a template resource / algorithm.
|
|
158
|
+
|
|
159
|
+
serve_html_file_from_disk(val, res);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
//throw 'stop';
|
|
163
|
+
} else {
|
|
164
|
+
//console.log('splitPath', splitPath);
|
|
165
|
+
//console.log('splitPath.length', splitPath.length);
|
|
166
|
+
|
|
167
|
+
if (splitPath.length > 0) {
|
|
168
|
+
|
|
169
|
+
// Can check for /js folder.
|
|
170
|
+
// There will be some fixed resources for the site.
|
|
171
|
+
// They will be served by Resource objects.
|
|
172
|
+
// There may be some overlap of resources, with there being some very fixed purpose
|
|
173
|
+
// specific resources that could duplicate some features of the more general ones.
|
|
174
|
+
// Eventually, some of the code from the more specific resources will be
|
|
175
|
+
// replacable with code from the more general ones.
|
|
176
|
+
|
|
177
|
+
// Site_JavaScript resource
|
|
178
|
+
// Will serve JavaScript files needed for the site.
|
|
179
|
+
// Could become more advanced at some points, serving particular builds.
|
|
180
|
+
|
|
181
|
+
if (splitPath.length == 1) {
|
|
182
|
+
if (splitPath[0] == '') {
|
|
183
|
+
// Serve the default page.
|
|
184
|
+
// serve index.html
|
|
185
|
+
//serve_html_file_from_disk('./index.html', res);
|
|
186
|
+
serve_html_file_from_disk('index.html', res);
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
}
|
|
192
|
+
} else {
|
|
193
|
+
if (splitPath[0] == 'html') {
|
|
194
|
+
//var sjs = pool.get_resource('Site JavaScript');
|
|
195
|
+
//console.log('sjs ' + sjs);
|
|
196
|
+
|
|
197
|
+
//throw 'stop';
|
|
198
|
+
|
|
199
|
+
// determine the name of the file to serve, serve that file
|
|
200
|
+
// Could use some more general kind of file server.
|
|
201
|
+
|
|
202
|
+
if (splitPath.length > 1) {
|
|
203
|
+
if (splitPath.length == 2) {
|
|
204
|
+
var fileName = splitPath[1];
|
|
205
|
+
//console.log('url_parts.path ' + url_parts.path);
|
|
206
|
+
var filePath = url_parts.path.substr(1);
|
|
207
|
+
//console.log('module.uri ' + module.uri);
|
|
208
|
+
|
|
209
|
+
// No, need the current module's relative path....
|
|
210
|
+
|
|
211
|
+
//var val2 = path.dirname(module.uri);
|
|
212
|
+
//console.log('val2 ' + val2);
|
|
213
|
+
//throw '9) stop';
|
|
214
|
+
|
|
215
|
+
//var diskPath = val2 + '/../css/' + fileName;
|
|
216
|
+
var diskPath = '../../ws/css/' + fileName;
|
|
217
|
+
|
|
218
|
+
serve_html_file_from_disk(diskPath, res);
|
|
219
|
+
} else {
|
|
220
|
+
if (splitPath.length == 3) {
|
|
221
|
+
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
module.exports = Site_Template_HTML;
|