jsgui3-server 0.0.98 → 0.0.100
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/examples/box/{square_box_client.js → 1) square box/client.js } +40 -5
- package/examples/box/{square_box.js → 1) square box/server.js } +10 -3
- package/examples/box/2) twenty square boxes/css flex wrap/client.js +248 -0
- package/examples/box/2) twenty square boxes/css flex wrap/server.js +113 -0
- package/examples/controls/1) window/client.js +184 -0
- package/examples/controls/1) window/server.js +114 -0
- package/examples/controls/{_html-server-color-palette.js → __old/_html-server-color-palette.js} +2 -2
- package/examples/controls/{scs-month-view.js → __old/scs-month-view.js} +0 -1
- package/http/responders/HTTP_Responder.js +16 -0
- package/http/responders/static/Static_Route_HTTP_Responder.js +106 -0
- package/package.json +9 -8
- package/page-context.js +15 -0
- package/publishers/helpers/assigners/Assigner.js +11 -0
- package/publishers/helpers/assigners/static-compressed-response-buffers/Single_Control_Webpage_Server_Static_Compressed_Response_Buffers_Assigner.js +150 -0
- package/publishers/helpers/assigners/static-headers/Single_Control_Webpage_Server_Static_Headers_Assigner.js +110 -0
- package/publishers/helpers/assigners/static-routes/Single_Control_Webpage_Server_Static_Routes_Assigner.js +92 -0
- package/publishers/helpers/assigners/static-uncompressed-response-buffers/Single_Control_Webpage_Server_Static_Uncompressed_Response_Buffers_Assigner.js +104 -0
- package/publishers/helpers/preparers/static/bundle/Ready_To_Serve_Preparer.js +19 -0
- package/publishers/helpers/preparers/static/bundle/Static_Routes_Responses_Webpage_Bundle_Preparer.js +45 -0
- package/publishers/http-webpage-publisher.js +483 -3
- package/publishers/http-webpageorsite-publisher.js +343 -0
- package/publishers/http-website-publisher.js +51 -2
- package/resources/compile/server-resource-compilation.js +2 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_0-Core.js +26 -0
- package/resources/processors/bundlers/css-bundler.js +24 -1
- package/resources/processors/bundlers/js/JS_Bundler.js +52 -0
- package/resources/processors/bundlers/js/esbuild/Advanced_JS_Bundler_Using_ESBuild.js +389 -0
- package/resources/processors/bundlers/js/esbuild/Bundler_Using_ESBuild.js +9 -0
- package/resources/processors/bundlers/js/esbuild/Core_JS_Non_Minifying_Bundler_Using_ESBuild.js +186 -0
- package/resources/processors/bundlers/js/esbuild/Core_JS_Single_File_Minifying_Bundler_Using_ESBuild.js +191 -0
- package/resources/processors/bundlers/js/esbuild/_Old_CSS_Extractor.js +240 -0
- package/resources/processors/bundlers/js-bundler.js +201 -193
- package/resources/processors/bundlers/webpage-bundler.js +15 -0
- package/resources/processors/extractors/Extractor.js +10 -0
- package/resources/processors/extractors/js/css_and_js/AST_Node/CSS_And_JS_From_JS_String_Using_AST_Node_Extractor.js +239 -0
- package/resources/processors/extractors/js/css_and_js/CSS_And_JS_From_JS_String_Extractor.js +4 -0
- package/resources/processors/extractors/string/Pos_Span_String_Extractor.js +94 -0
- package/server.js +188 -5
- package/static-page-context.js +14 -0
- package/examples/box/box.css +0 -8
- package/examples/box/out_square_box_client.js +0 -48
- /package/examples/controls/{html-server-combo-box.js → __old/html-server-combo-box.js} +0 -0
- /package/examples/controls/{html-server-list.js → __old/html-server-list.js} +0 -0
- /package/examples/controls/{html-server-popup-menu-button.js → __old/html-server-popup-menu-button.js} +0 -0
- /package/examples/controls/{html-server-start-stop-toggle-button.js → __old/html-server-start-stop-toggle-button.js} +0 -0
- /package/examples/controls/{scs-arrow-button.js → __old/scs-arrow-button.js} +0 -0
- /package/examples/controls/{scs-date-picker.js → __old/scs-date-picker.js} +0 -0
- /package/examples/controls/{scs-file-browser.js → __old/scs-file-browser.js} +0 -0
- /package/examples/controls/{scs-item.js → __old/scs-item.js} +0 -0
- /package/examples/controls/{scs-month-arrow-selector.js → __old/scs-month-arrow-selector.js} +0 -0
- /package/examples/controls/{scs-start-stop-toggle-button.js → __old/scs-start-stop-toggle-button.js} +0 -0
- /package/examples/controls/{scs-tree.js → __old/scs-tree.js} +0 -0
- /package/examples/controls/{scs-year-arrow-selector.js → __old/scs-year-arrow-selector.js} +0 -0
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
// Extract the CSS and JS from JS, using AST_Node.
|
|
4
|
+
// AST_Node is part of jsgui3-server, possibly too slow though.
|
|
5
|
+
|
|
6
|
+
const {obs, prom_or_cb} = require('fnl');
|
|
7
|
+
const {tof, each} = require('jsgui3-html');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
const JS_AST_Node = require('../../../../../jsbuilder/JS_AST/JS_AST_Node');
|
|
11
|
+
const Extractor = require('../../../Extractor');
|
|
12
|
+
|
|
13
|
+
const Pos_Span_String_Extractor = require('../../../string/Pos_Span_String_Extractor');
|
|
14
|
+
|
|
15
|
+
// Seems like a really specific and JS-AST aware algorithm.
|
|
16
|
+
// The JS AST parsing (single thread JS, maybe inefficient class structure) is relatively slow, but much faster than Babel compilation
|
|
17
|
+
// was / is.
|
|
18
|
+
|
|
19
|
+
// const String_Pos_Spans_Remover = ....
|
|
20
|
+
|
|
21
|
+
// Really specifically named and categorised classes will be a main feature of this part of the (Server) architecture.
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
// But also being able to recreate the AST without the CSS will help.
|
|
29
|
+
|
|
30
|
+
// This extraction extracts parts from the JS file that directly are CSS.
|
|
31
|
+
// I don't think at the moment it does anything further than that - though want it to remove all the declarations of CSS
|
|
32
|
+
// from the JS and return that JS.
|
|
33
|
+
|
|
34
|
+
// See about removing the nodes from the tree....
|
|
35
|
+
|
|
36
|
+
class CSS_And_JS_From_JS_String_Using_AST_Node_Extractor extends Extractor {
|
|
37
|
+
constructor(spec) {
|
|
38
|
+
super(spec);
|
|
39
|
+
|
|
40
|
+
this.pos_span_string_extractor = new Pos_Span_String_Extractor();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
extract(str_js) {
|
|
44
|
+
const {pos_span_string_extractor} = this;
|
|
45
|
+
|
|
46
|
+
const js_str = str_js;
|
|
47
|
+
return obs((next, complete, error) => {
|
|
48
|
+
const spec = {
|
|
49
|
+
source: js_str
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// This part is kind-of slow.
|
|
53
|
+
|
|
54
|
+
console.log('pre create js ast node');
|
|
55
|
+
const js_ast_node = JS_AST_Node.from_spec(spec);
|
|
56
|
+
console.log('post create js ast node');
|
|
57
|
+
|
|
58
|
+
//const ae_nodes = [];
|
|
59
|
+
|
|
60
|
+
const arr_pos_spans_css_js_nodes = []; // will remove them from the JS that's built / published.
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
// Just assigning a template literal to .css?
|
|
66
|
+
const css_ae_nodes = [];
|
|
67
|
+
|
|
68
|
+
// How about removing those parts from the JS AST?
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
js_ast_node.deep_iterate(node => {
|
|
73
|
+
|
|
74
|
+
const {start, end} = node.babel;
|
|
75
|
+
|
|
76
|
+
// Maybe this part is slow? Don't think so though.
|
|
77
|
+
|
|
78
|
+
//console.log('node', node);
|
|
79
|
+
//console.log('Object.keys(node)', Object.keys(node));
|
|
80
|
+
//console.log('node.type_signature', node.type_signature);
|
|
81
|
+
//console.log('node.signature', node.signature);
|
|
82
|
+
//console.log('node.type', node.type);
|
|
83
|
+
//console.log('node.abbreviated_type', node.abbreviated_type);
|
|
84
|
+
|
|
85
|
+
if (node.type === 'AssignmentExpression') {
|
|
86
|
+
//return true;
|
|
87
|
+
//ae_nodes.push(node);
|
|
88
|
+
//console.log('node.source', node.source);
|
|
89
|
+
|
|
90
|
+
//console.log('Object.keys(node.babel)', Object.keys(node.babel));
|
|
91
|
+
|
|
92
|
+
//console.log('node.child_nodes.length', node.child_nodes.length);
|
|
93
|
+
|
|
94
|
+
const [node_assigned_to, node_assigned] = node.child_nodes;
|
|
95
|
+
//console.log('node_assigned_to.source', node_assigned_to.source);
|
|
96
|
+
//console.log('node_assigned_to.type', node_assigned_to.type);
|
|
97
|
+
//console.log('node_assigned.type', node_assigned.type);
|
|
98
|
+
|
|
99
|
+
if (node_assigned.type === 'TemplateLiteral') {
|
|
100
|
+
|
|
101
|
+
if (node_assigned_to.type === 'MemberExpression') {
|
|
102
|
+
|
|
103
|
+
//console.log('node_assigned_to', node_assigned_to);
|
|
104
|
+
|
|
105
|
+
// the last ID being .css?
|
|
106
|
+
const last_me_child = node_assigned_to.child_nodes[node_assigned_to.child_nodes.length - 1];
|
|
107
|
+
//console.log('last_me_child', last_me_child);
|
|
108
|
+
//console.log('last_me_child.source', last_me_child.source);
|
|
109
|
+
|
|
110
|
+
if (last_me_child.source === 'css') {
|
|
111
|
+
css_ae_nodes.push(node);
|
|
112
|
+
|
|
113
|
+
//console.log('[start, end]', [start, end]);
|
|
114
|
+
//console.log('node.source:\n' + node.source + '\n');
|
|
115
|
+
|
|
116
|
+
arr_pos_spans_css_js_nodes.push([start, end]);
|
|
117
|
+
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// does it end '.css'?
|
|
121
|
+
// break it down further?
|
|
122
|
+
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
///console.log('node.source', node.source);
|
|
126
|
+
//throw 'stop';
|
|
127
|
+
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
//console.log('');
|
|
131
|
+
// look at the left part...
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
//throw 'stop';
|
|
135
|
+
});
|
|
136
|
+
//console.log('ae_nodes', ae_nodes);
|
|
137
|
+
//console.log('ae_nodes.length', ae_nodes.length);
|
|
138
|
+
//console.log('css_ae_nodes.length', css_ae_nodes.length);
|
|
139
|
+
|
|
140
|
+
const arr_css = [];
|
|
141
|
+
|
|
142
|
+
if (css_ae_nodes.length > 0) {
|
|
143
|
+
//console.log('css_ae_nodes', css_ae_nodes);
|
|
144
|
+
|
|
145
|
+
each(css_ae_nodes, css_ae_node => {
|
|
146
|
+
//console.log('css_ae_node.source', css_ae_node.source);
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
const tl = css_ae_node.child_nodes[1].child_nodes[0];
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
//console.log('tl', tl);
|
|
153
|
+
//console.log('tl.source', tl.source);
|
|
154
|
+
arr_css.push(tl.source);
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
})
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (arr_css.length > 0) {
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
// Needs to also return the JS, without the CSS.
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
const str_css = arr_css.join('\n');
|
|
169
|
+
|
|
170
|
+
//console.log('arr_pos_spans_css_js_nodes', arr_pos_spans_css_js_nodes);
|
|
171
|
+
|
|
172
|
+
// Then see about removing the inverse of them from the original string.
|
|
173
|
+
|
|
174
|
+
const str_js_without_css_assignments = pos_span_string_extractor.extract(js_str, arr_pos_spans_css_js_nodes, {invert: true});
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
//console.log('str_js_without_css_assignments', str_js_without_css_assignments);
|
|
178
|
+
//console.log('str_js_without_css_assignments.length', str_js_without_css_assignments.length);
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
// return an array perhaps?
|
|
182
|
+
// object with keys may be easier / better / simpler.
|
|
183
|
+
// or even a Bundle object?
|
|
184
|
+
|
|
185
|
+
const res = {
|
|
186
|
+
css: str_css,
|
|
187
|
+
js: str_js_without_css_assignments
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
//console.trace();
|
|
194
|
+
//throw 'stop';
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
complete(res);
|
|
200
|
+
} else {
|
|
201
|
+
complete();
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
// Can then do query to get all .css properties that are string templates.
|
|
206
|
+
// is it a property of a Class object?
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
// Need to get an AST from it....
|
|
213
|
+
// Or could simply search (regex?) for .css = `...`?
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
// Go through each file? Just the first?
|
|
219
|
+
|
|
220
|
+
// Or should the whole bundled (browserified) JS be consulted?
|
|
221
|
+
|
|
222
|
+
const [stop, pause, resume] = [() => {}, () => {}, () => {}];
|
|
223
|
+
return [stop, pause, resume];
|
|
224
|
+
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// Then extract by giving it a JS string?
|
|
230
|
+
// A file path???
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
module.exports = CSS_And_JS_From_JS_String_Using_AST_Node_Extractor;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
const Extractor = require('../Extractor');
|
|
2
|
+
|
|
3
|
+
const invert_arr_pos_spans = (arr_pos_spans, str_len) => {
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
// Create the array of inverted ones...
|
|
7
|
+
// The one before the first.
|
|
8
|
+
// The gaps between each of them.
|
|
9
|
+
// The one after the last.
|
|
10
|
+
|
|
11
|
+
const res = [];
|
|
12
|
+
|
|
13
|
+
if (arr_pos_spans.length === 0) {
|
|
14
|
+
res.push([0, str_len]);
|
|
15
|
+
} else {
|
|
16
|
+
|
|
17
|
+
if (arr_pos_spans[0][0] > 0) {
|
|
18
|
+
res.push([0, arr_pos_spans[0][0]]);
|
|
19
|
+
} else {
|
|
20
|
+
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
if (arr_pos_spans.length > 1) {
|
|
26
|
+
// there are gaps
|
|
27
|
+
|
|
28
|
+
let i = 0;
|
|
29
|
+
// while there are remaining ones...?
|
|
30
|
+
|
|
31
|
+
for (i = 0; i < arr_pos_spans.length - 1; i++) {
|
|
32
|
+
res.push([arr_pos_spans[i][1], arr_pos_spans[i+1][0]])
|
|
33
|
+
}
|
|
34
|
+
//console.log('i', i);
|
|
35
|
+
res.push([arr_pos_spans[i][1], str_len])
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
} else if (arr_pos_spans.length === 1) {
|
|
40
|
+
res.push([arr_pos_spans[0][1], str_len])
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
return res;
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
class Pos_Span_String_Extractor extends Extractor {
|
|
62
|
+
constructor(spec) {
|
|
63
|
+
super(spec);
|
|
64
|
+
}
|
|
65
|
+
extract(str, arr_pos_spans, options = {}) {
|
|
66
|
+
|
|
67
|
+
// Possibly invert the arr_pos_spans
|
|
68
|
+
|
|
69
|
+
if (options.invert){
|
|
70
|
+
arr_pos_spans = invert_arr_pos_spans(arr_pos_spans, str.length);
|
|
71
|
+
|
|
72
|
+
console.log('inverted arr_pos_spans', arr_pos_spans);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
let arr_str_res = [];
|
|
76
|
+
|
|
77
|
+
// getting the strings within the arr_pos_spans....
|
|
78
|
+
|
|
79
|
+
const n_spans = arr_pos_spans.length;
|
|
80
|
+
for (let c = 0; c < n_spans; c++) {
|
|
81
|
+
const pos_span = arr_pos_spans[c];
|
|
82
|
+
arr_str_res.push(str.substring(pos_span[0], pos_span[1]));
|
|
83
|
+
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const str_res = arr_str_res.join('');
|
|
87
|
+
return str_res;
|
|
88
|
+
|
|
89
|
+
// Create a new span
|
|
90
|
+
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
module.exports = Pos_Span_String_Extractor;
|
package/server.js
CHANGED
|
@@ -33,7 +33,7 @@ const HTTP_Webpage_Publisher = require('./publishers/http-webpage-publisher');
|
|
|
33
33
|
// Multi_Single_Process_Server_Coordinater_Server ???
|
|
34
34
|
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
const Static_Route_HTTP_Responder = require('./http/responders/static/Static_Route_HTTP_Responder');
|
|
37
37
|
|
|
38
38
|
|
|
39
39
|
class JSGUI_Single_Process_Server extends Evented_Class {
|
|
@@ -50,6 +50,11 @@ class JSGUI_Single_Process_Server extends Evented_Class {
|
|
|
50
50
|
disk_path_client_js = spec.source_path_client_js;
|
|
51
51
|
};
|
|
52
52
|
|
|
53
|
+
|
|
54
|
+
if (spec.debug !== undefined) {
|
|
55
|
+
this.debug = spec.debug;
|
|
56
|
+
}
|
|
57
|
+
|
|
53
58
|
// or src_path_client_js as well...
|
|
54
59
|
|
|
55
60
|
Object.defineProperty(this, 'disk_path_client_js', {get: () => disk_path_client_js, set: (value) => disk_path_client_js = value});
|
|
@@ -89,6 +94,8 @@ class JSGUI_Single_Process_Server extends Evented_Class {
|
|
|
89
94
|
|
|
90
95
|
// Seems like a decent mechanism already in here at the moment, but may want to make the API more powerful and flexible.
|
|
91
96
|
|
|
97
|
+
// A single Ctrl that represents a page (could a Ctrl represent a site too? Could be possible with a bit of work.)
|
|
98
|
+
|
|
92
99
|
|
|
93
100
|
|
|
94
101
|
if (Ctrl) {
|
|
@@ -161,12 +168,22 @@ class JSGUI_Single_Process_Server extends Evented_Class {
|
|
|
161
168
|
|
|
162
169
|
const opts_wp_publisher = {
|
|
163
170
|
'webpage': wp_app
|
|
171
|
+
|
|
164
172
|
};
|
|
165
173
|
|
|
174
|
+
if (this.debug) {
|
|
175
|
+
opts_wp_publisher.debug = this.debug;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (disk_path_client_js) opts_wp_publisher.src_path_client_js = disk_path_client_js;
|
|
179
|
+
|
|
166
180
|
|
|
167
181
|
|
|
168
182
|
// HTTP_Webpage_Publisher probably needs to build the JavaScript. Possibly other assets too.
|
|
169
183
|
const wp_publisher = new HTTP_Webpage_Publisher(opts_wp_publisher);
|
|
184
|
+
// Specific options for when that publisher is in debug mode.
|
|
185
|
+
|
|
186
|
+
|
|
170
187
|
console.log('waiting for wp_publisher ready');
|
|
171
188
|
|
|
172
189
|
// Server can (maybe just in theory) serve multiple websites at once.
|
|
@@ -175,24 +192,188 @@ class JSGUI_Single_Process_Server extends Evented_Class {
|
|
|
175
192
|
// Then does the website resource contain a lot of its own resources, in a pool???
|
|
176
193
|
|
|
177
194
|
|
|
195
|
+
// The publisher should (probably) set things up with the server itself....
|
|
196
|
+
// Give the publisher access to the server.
|
|
197
|
+
// Or access to a more limited number of functions that the publisher can call.
|
|
198
|
+
|
|
199
|
+
// So the Publisher itself finds the Server Router and sets up routes on it, but uses very specific classes to help do that.
|
|
200
|
+
|
|
201
|
+
// Maybe Http_Publisher on a lower level could put together headers and do compression.
|
|
202
|
+
// This part will be a little more like Express (and other) middleware.
|
|
203
|
+
|
|
204
|
+
// http_publisher.publish_static_content_to_routes
|
|
205
|
+
// .publish_static_bundle_to_routes
|
|
178
206
|
|
|
179
207
|
|
|
180
|
-
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
wp_publisher.on('ready', (wp_ready_res) => {
|
|
181
216
|
console.log('wp publisher is ready');
|
|
182
217
|
|
|
218
|
+
// The ready res on complete(res) ???
|
|
219
|
+
// But the ready event does not (easily) carry this object.
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
//console.log('wp_ready_res', wp_ready_res);
|
|
223
|
+
|
|
224
|
+
// then go through the array....
|
|
225
|
+
|
|
226
|
+
if (wp_ready_res._arr) {
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
for (const bundle_item of wp_ready_res._arr) {
|
|
230
|
+
//console.log('Object.keys(bundle_item)', Object.keys(bundle_item));
|
|
183
231
|
|
|
232
|
+
|
|
184
233
|
|
|
185
|
-
|
|
234
|
+
const {type, extension, text, route, response_buffers, response_headers} = bundle_item;
|
|
235
|
+
//console.log('');
|
|
236
|
+
//console.log('bundle_item route:', route);
|
|
237
|
+
//console.log('bundle_item type:', type);
|
|
238
|
+
|
|
239
|
+
const bundle_item_http_responder = new Static_Route_HTTP_Responder(bundle_item);
|
|
240
|
+
|
|
241
|
+
//console.log('bundle_item_http_responder.handle_http', bundle_item_http_responder.handle_http);
|
|
242
|
+
|
|
243
|
+
// So set_route needs to set it up with the proper context for the handle_http call.
|
|
244
|
+
// At least it looks fairly close to being solved, though maybe Router and Routing tree
|
|
245
|
+
// should have comprehensive fixes and improvements.
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
server_router.set_route(route, bundle_item_http_responder, bundle_item_http_responder.handle_http);
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
//console.trace();
|
|
255
|
+
//throw 'stop';
|
|
256
|
+
|
|
257
|
+
} else {
|
|
258
|
+
console.trace();
|
|
259
|
+
throw 'NYI';
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// But do we get a bundle from it when ready?
|
|
263
|
+
// Maybe it should provide that bundle in the 'ready' event.
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
const ws_resource = new Website_Resource({
|
|
186
269
|
'name': 'Website_Resource - Single Webpage',
|
|
187
270
|
'webpage': wp_app
|
|
188
271
|
});
|
|
189
|
-
resource_pool.add(
|
|
190
|
-
|
|
272
|
+
resource_pool.add(ws_resource);
|
|
273
|
+
|
|
274
|
+
//
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
// Possibly set multiple routes here, with multiple response buffers depending on the encoding-type
|
|
278
|
+
// accepted by the client.
|
|
279
|
+
|
|
280
|
+
// Seems best not to rely on the Webpage_Publisher to handle the HTTP.
|
|
281
|
+
// Better for the Publisher to create the Bundle that is ready to serve, than provide that
|
|
282
|
+
// to the Server here, or maybe to something else.
|
|
283
|
+
|
|
284
|
+
// Seems best to get that ready to serve static bundle from the publisher,
|
|
285
|
+
// and if it helps use some kind of system to set up some more details with the server router...?
|
|
286
|
+
|
|
287
|
+
// Initial_Response_Handler perhaps?
|
|
288
|
+
|
|
289
|
+
// Webpage_HTTP_Response_Handler?
|
|
290
|
+
|
|
291
|
+
// Static_Webpage_HTTP_Response_Handler???
|
|
292
|
+
|
|
293
|
+
// Static_Webpage_Bundle_HTTP_Response_Handler ???
|
|
294
|
+
|
|
295
|
+
// Static_Webpage_Bundle_HTTP_Route_Response_Handler ????
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
// Static_Webpage_Bundle_HTTP_Route_Responder ???
|
|
299
|
+
|
|
300
|
+
// new Static_Webpage_Bundle_HTTP_Route_Responder(bundle_item)
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
// Static_Webpage_Bundle_HTTP_Responder ??? (would do routing / route checking itself perhaps?)
|
|
306
|
+
// Seems like for the moment we should continue to use the server router.
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
// Need to decide which encoded (compressed) buffer to return depending
|
|
312
|
+
// on what Content-Type(s) are supported on the client.
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
// Very explicit class names make the responsibilities very clear.
|
|
318
|
+
|
|
319
|
+
// Static_Route_HTTP_Responder seems best to provide the handle_http function.
|
|
320
|
+
// Even after routing a decision needs to be made regarding which buffer to send to the client
|
|
321
|
+
// Should be the last thing needed to get this simple square box demo server working properly.
|
|
322
|
+
// Hopefully the client-side activation still works fine.
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
// HTTP_Responder class and subclasses???
|
|
327
|
+
// Could be a helpful type of middleware.
|
|
328
|
+
// Want to have it handle creating or using the correct compressed buffer.
|
|
329
|
+
|
|
330
|
+
// go through the array of bundle items....
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
// Need the bundle object / array here.
|
|
334
|
+
// Would be nice to have the bundle itself hold info on what's inside.
|
|
335
|
+
// Incl what packaging stage it is at, how ready to serve.
|
|
336
|
+
|
|
337
|
+
// Though possible one object could handle the whole static bundle setup with the router...?
|
|
338
|
+
|
|
339
|
+
// The code in a loop should be simple enough here though.
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
// Set the routes of the various items in the bundle (and use the handlers provided by class
|
|
349
|
+
// instance objects that specifically provide HTTP handlers)
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
// Should be the very last part of serving the HTTP for this particular server type.
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
//server_router.set_route('/', wp_publisher, wp_publisher.handle_http);
|
|
365
|
+
|
|
366
|
+
|
|
191
367
|
this.raise('ready');
|
|
192
368
|
});
|
|
193
369
|
|
|
194
370
|
|
|
195
371
|
} else {
|
|
372
|
+
|
|
373
|
+
// Ahhh the web page publisher may be used instead of the website publisher.
|
|
374
|
+
// See about making use of relevant shared abstractions.
|
|
375
|
+
|
|
376
|
+
|
|
196
377
|
const ws_app = this.app = new Website(opts_website);
|
|
197
378
|
// Be able to treat Webpage as an app?
|
|
198
379
|
|
|
@@ -297,6 +478,8 @@ JSGUI_Single_Process_Server.Page_Context = Server_Page_Context;
|
|
|
297
478
|
JSGUI_Single_Process_Server.Server_Page_Context = Server_Page_Context;
|
|
298
479
|
JSGUI_Single_Process_Server.Website_Resource = Website_Resource;
|
|
299
480
|
module.exports = JSGUI_Single_Process_Server;
|
|
481
|
+
|
|
482
|
+
|
|
300
483
|
if (require.main === module) {
|
|
301
484
|
const args = process.argv.slice(2);
|
|
302
485
|
let port = 80;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const Server_Page_Context = require('./page-context');
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class Server_Static_Page_Context extends Server_Page_Context {
|
|
5
|
+
constructor(spec = {}) {
|
|
6
|
+
//spec = spec || {};
|
|
7
|
+
super(spec);
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
module.exports = Server_Static_Page_Context;
|