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,114 @@
|
|
|
1
|
+
const jsgui = require('./client');
|
|
2
|
+
|
|
3
|
+
const {Demo_UI, Square_Box} = jsgui.controls;
|
|
4
|
+
const Server = require('../../../server');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
// what would be the (best?) way to include the whole thing in one JS file?
|
|
8
|
+
// Maybe don't try that right now.
|
|
9
|
+
// maybe standardise on the dir, then client.js and server.js inside.
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
// Want to exclude this from the client bundle.
|
|
14
|
+
// Some kind of marking to say that it's server-side only?
|
|
15
|
+
|
|
16
|
+
// Need to include JSGUI3 js within the client document.
|
|
17
|
+
// Seems like an earlier code simplification removed this functionality?
|
|
18
|
+
// Just specifying a Ctrl for the server - and giving it the 'disk_path_client_js'.
|
|
19
|
+
// May as well fix that....
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
if (require.main === module) {
|
|
26
|
+
|
|
27
|
+
// By default should include the JS and the CSS.
|
|
28
|
+
// By reference, serving them from their respective paths.
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
// This API is not working right now.
|
|
32
|
+
|
|
33
|
+
// A very simple syntax for running a single control would be great.
|
|
34
|
+
|
|
35
|
+
// Need to in the default (server) configuration build and serve the client-side app.
|
|
36
|
+
// Want to be able to make interactive apps quickly with minimal server side code that needs to be written as boilerplate to
|
|
37
|
+
// get the app running.
|
|
38
|
+
|
|
39
|
+
// Though maybe defining a webpage, that serves the client js, and renders the control on the server, and activates it on the client,
|
|
40
|
+
// would be the right approach.
|
|
41
|
+
|
|
42
|
+
// Want to make the code really explicit, in a simple way.
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
// eg { '/': Demo_UI }
|
|
46
|
+
// eg { '*': Demo_UI }
|
|
47
|
+
// as at least it explicitly assigns it to the '/' route
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
// But worth keeping the '/' Ctrl property?
|
|
51
|
+
// Could change it to explicitly setting the route(s).
|
|
52
|
+
|
|
53
|
+
// Do want it to build the client js on start.
|
|
54
|
+
|
|
55
|
+
// Could extract the CSS from the file itself, or maybe better reading it from the classes and objects that are loaded / referenced.
|
|
56
|
+
// All kinds of complex server program structures exist already, so could use Publishers if needed for some things.
|
|
57
|
+
// But need to keep the surface-level API really simple.
|
|
58
|
+
|
|
59
|
+
// Maybe define a Webpage and maybe use / define an HTML_Webpage_Publisher for example too.
|
|
60
|
+
// The clearest code would be really explicit about what it does, but in terms of almost English idioms
|
|
61
|
+
// and on the surface-level not spelling out in great detail what it's doing, but referencing objects and
|
|
62
|
+
// instructions with clear purposes, though details could be obscure at the top level. Eg it's the publisher's responsibility
|
|
63
|
+
// to include the CSS and JS that's needed to get it to run. A publisher is referenced and used, and it does its thing.
|
|
64
|
+
|
|
65
|
+
// The Server could automatically involk the use of a Publisher.
|
|
66
|
+
// May be better to either require or recommend more explicit code, have them in the examples,
|
|
67
|
+
// but also to document some shortcuts, defaults, and abbreviations (though they may omit some essential info, so not recommended for beginners)
|
|
68
|
+
|
|
69
|
+
// Could have a tabbed view for examples for 'explicit' and 'short' notations when there are multiple.
|
|
70
|
+
|
|
71
|
+
// jsgui3-html-suite may be of use, for some more extended controls that are built on top of jsgui3-html, but not specifically
|
|
72
|
+
// client or server.
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
const server = new Server({
|
|
80
|
+
Ctrl: Demo_UI,
|
|
81
|
+
// Giving it the Ctrl and disk path client js should enable to server to get the JS-bundled CSS from the file(s).
|
|
82
|
+
// Putting the JS files through proper parsing and into a syntax tree would be best.
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
//'js_mode': 'debug',
|
|
86
|
+
'src_path_client_js': require.resolve('./client.js'),
|
|
87
|
+
debug: true // should not minify the js, should include the symbols.
|
|
88
|
+
//js_client: require.resolve('./square_box.js')
|
|
89
|
+
});
|
|
90
|
+
// A callback or event for when the bundling has been completed
|
|
91
|
+
// a 'ready' event.
|
|
92
|
+
|
|
93
|
+
// then start the server....
|
|
94
|
+
// be able to choose the port / ports?
|
|
95
|
+
console.log('waiting for server ready event');
|
|
96
|
+
server.on('ready', () => {
|
|
97
|
+
console.log('server ready');
|
|
98
|
+
|
|
99
|
+
// server start will change to observable?
|
|
100
|
+
|
|
101
|
+
server.start(8080, function (err, cb_start) {
|
|
102
|
+
if (err) {
|
|
103
|
+
throw err;
|
|
104
|
+
} else {
|
|
105
|
+
// Should have build it by now...
|
|
106
|
+
|
|
107
|
+
console.log('server started');
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
}
|
package/examples/controls/{_html-server-color-palette.js → __old/_html-server-color-palette.js}
RENAMED
|
@@ -17,9 +17,9 @@ var jsgui = require('jsgui3-html');
|
|
|
17
17
|
var Start_Stop_Toggle_Button = jsgui.Start_Stop_Toggle_Button;
|
|
18
18
|
var Color_Palette = jsgui.Color_Palette;
|
|
19
19
|
|
|
20
|
-
var Server = require('
|
|
20
|
+
var Server = require('../../../server');
|
|
21
21
|
var port = 8000;
|
|
22
|
-
var Server_Page_Context = require('
|
|
22
|
+
var Server_Page_Context = require('../../../page-context');
|
|
23
23
|
|
|
24
24
|
var server = new Server({
|
|
25
25
|
'routes': {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
|
|
2
|
+
const {tof} = require('lang-tools');
|
|
3
|
+
|
|
4
|
+
class HTTP_Responder {
|
|
5
|
+
constructor(spec) {
|
|
6
|
+
const t_spec = tof(spec);
|
|
7
|
+
if (t_spec === 'object') {
|
|
8
|
+
Object.assign(this, spec);
|
|
9
|
+
} else {
|
|
10
|
+
console.trace();
|
|
11
|
+
throw 'stop';
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
module.exports = HTTP_Responder;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
|
|
2
|
+
const HTTP_Responder = require('../HTTP_Responder');
|
|
3
|
+
|
|
4
|
+
// Looks like some Router bug fix is needed...?
|
|
5
|
+
// Need to remove the first '/' from the route???
|
|
6
|
+
// Or fix / modify the jsgui3-html Router so it does that?
|
|
7
|
+
|
|
8
|
+
// May need to see how it's being put into the router.
|
|
9
|
+
// Perhaps don't want to use a tree in some / many instances.
|
|
10
|
+
|
|
11
|
+
// Maybe fixing and updating the routing tree is worthwhile at this stage.
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class Static_Route_HTTP_Responder extends HTTP_Responder {
|
|
18
|
+
constructor(spec) {
|
|
19
|
+
super(spec);
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
//console.log('Static_Route_HTTP_Responder spec:', spec);
|
|
23
|
+
|
|
24
|
+
//console.trace();
|
|
25
|
+
//throw 'NYI';
|
|
26
|
+
|
|
27
|
+
// type,
|
|
28
|
+
|
|
29
|
+
// Give it the bundle object as spec...?
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
}
|
|
33
|
+
handle_http(req, res) {
|
|
34
|
+
const r_headers = req.headers;
|
|
35
|
+
const accept_encoding = r_headers['accept-encoding'];
|
|
36
|
+
|
|
37
|
+
// Need to call it with the correct context.
|
|
38
|
+
// Seems like jsgui3-html Router and Routing_Tree need some more fixes.
|
|
39
|
+
|
|
40
|
+
const {type, extension, text, route, response_buffers, response_headers} = this;
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
//console.log('accept_encoding', accept_encoding);
|
|
44
|
+
|
|
45
|
+
//console.log('typeof accept_encoding', typeof accept_encoding);
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
// See about 'gzip'.
|
|
50
|
+
// Not sure why br does not show up as normal.
|
|
51
|
+
|
|
52
|
+
const supported_encodings = {};
|
|
53
|
+
|
|
54
|
+
if (accept_encoding.includes('gzip')) supported_encodings.gzip = true;
|
|
55
|
+
|
|
56
|
+
if (accept_encoding.includes('br')) supported_encodings.br = true;
|
|
57
|
+
|
|
58
|
+
//console.log('supported_encodings', supported_encodings);
|
|
59
|
+
|
|
60
|
+
if (supported_encodings.br === true) {
|
|
61
|
+
|
|
62
|
+
for (const key in response_headers.br) {
|
|
63
|
+
const value = response_headers.br[key];
|
|
64
|
+
//console.log('[key, value]', [key, value]);
|
|
65
|
+
res.setHeader(key, value);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
} else if (supported_encodings.gzip === true) {
|
|
69
|
+
//console.log('should write headers for gzipped buffer...');
|
|
70
|
+
|
|
71
|
+
for (const key in response_headers.gzip) {
|
|
72
|
+
const value = response_headers.gzip[key];
|
|
73
|
+
//console.log('[key, value]', [key, value]);
|
|
74
|
+
res.setHeader(key, value);
|
|
75
|
+
}
|
|
76
|
+
} else {
|
|
77
|
+
for (const key in response_headers.identity) {
|
|
78
|
+
const value = response_headers.identity[key];
|
|
79
|
+
//console.log('[key, value]', [key, value]);
|
|
80
|
+
res.setHeader(key, value);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Then write the (hopefully compressed) response bodies...
|
|
85
|
+
|
|
86
|
+
if (supported_encodings.br === true) {
|
|
87
|
+
|
|
88
|
+
res.write(response_buffers.br);
|
|
89
|
+
res.write(response_buffers.br);
|
|
90
|
+
} else if (supported_encodings.gzip === true) {
|
|
91
|
+
//console.log('should write gzipped buffer...');
|
|
92
|
+
res.write(response_buffers.gzip);
|
|
93
|
+
} else {
|
|
94
|
+
res.write(response_buffers.identity);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
res.end();
|
|
98
|
+
|
|
99
|
+
//console.trace();
|
|
100
|
+
//throw 'NYI';
|
|
101
|
+
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
module.exports = Static_Route_HTTP_Responder;
|
package/package.json
CHANGED
|
@@ -11,16 +11,17 @@
|
|
|
11
11
|
"browserify": "17.0.0",
|
|
12
12
|
"child-process": "^1.0.2",
|
|
13
13
|
"cookies": "^0.8.0",
|
|
14
|
-
"esbuild": "^0.19.
|
|
15
|
-
"fnl": "^0.0.
|
|
16
|
-
"fnlfs": "^0.0.
|
|
17
|
-
"jsgui3-client": "^0.0.
|
|
18
|
-
"jsgui3-webpage": "^0.0.
|
|
19
|
-
"jsgui3-website": "^0.0.
|
|
14
|
+
"esbuild": "^0.19.4",
|
|
15
|
+
"fnl": "^0.0.29",
|
|
16
|
+
"fnlfs": "^0.0.29",
|
|
17
|
+
"jsgui3-client": "^0.0.84",
|
|
18
|
+
"jsgui3-webpage": "^0.0.6",
|
|
19
|
+
"jsgui3-website": "^0.0.6",
|
|
20
|
+
"lang-tools": "^0.0.17",
|
|
20
21
|
|
|
21
22
|
"multiparty": "^4.2.3",
|
|
22
23
|
"ncp": "^2.0.0",
|
|
23
|
-
"obext": "^0.0.
|
|
24
|
+
"obext": "^0.0.27",
|
|
24
25
|
"rimraf": "^3.0.2",
|
|
25
26
|
"stream-to-array": "^2.3.0",
|
|
26
27
|
"url-parse": "^1.5.10"
|
|
@@ -44,5 +45,5 @@
|
|
|
44
45
|
"type": "git",
|
|
45
46
|
"url": "https://github.com/metabench/jsgui3-server.git"
|
|
46
47
|
},
|
|
47
|
-
"version": "0.0.
|
|
48
|
+
"version": "0.0.100"
|
|
48
49
|
}
|
package/page-context.js
CHANGED
|
@@ -6,6 +6,21 @@ var Class = jsgui.Class, Data_Object = jsgui.Data_Object;
|
|
|
6
6
|
var fp = jsgui.fp, is_defined = jsgui.is_defined;
|
|
7
7
|
var get_a_sig = jsgui.get_a_sig;
|
|
8
8
|
|
|
9
|
+
|
|
10
|
+
// Server_Static_Page_Context could help just by the more explicit name.
|
|
11
|
+
// Used for a single rendering.
|
|
12
|
+
|
|
13
|
+
// Will not be in the context of a request and response.
|
|
14
|
+
// Though could help with creating a response that can be reused.
|
|
15
|
+
|
|
16
|
+
// Think we should continue making the various (very specific) bits and pieces that represent all parts of the process.
|
|
17
|
+
|
|
18
|
+
//
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
9
24
|
// Need to find out what this one requires to put it in its own module.
|
|
10
25
|
class Server_Page_Context extends jsgui.Page_Context {
|
|
11
26
|
constructor(spec) {
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
// Making such specific classes with such long names seems kind of silly, but will help to keep the higher level code
|
|
4
|
+
// both explicit and easy to follow.
|
|
5
|
+
|
|
6
|
+
// These classes will do specific things, to specific things (in specific ways)
|
|
7
|
+
|
|
8
|
+
// Basically middleware that the app dev should not need to pay much attention to usually.
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
// And likely will have some other class (system), maybe assigners, to set the routes on the server / server router.
|
|
14
|
+
// Or within the website resource???
|
|
15
|
+
|
|
16
|
+
// So everything (main) that the server does will be done using various interchangable classes.
|
|
17
|
+
// Some classes will cover some very specific use cases.
|
|
18
|
+
|
|
19
|
+
const zlib = require('zlib');
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
const Assigner = require('../Assigner');
|
|
24
|
+
|
|
25
|
+
const {is_array} = require('lang-tools');
|
|
26
|
+
|
|
27
|
+
// And will have some very or less specific assigners for some other things.
|
|
28
|
+
// Like the compressed (text?) response headers.
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
const { promisify } = require('node:util');
|
|
32
|
+
|
|
33
|
+
// deflate, unzip
|
|
34
|
+
|
|
35
|
+
const gzip_compress = promisify(zlib.gzip);
|
|
36
|
+
const br_compress = promisify(zlib.brotliCompress);
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
// zlib.gzip(buffer[, options], callback)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class Single_Control_Webpage_Server_Static_Compressed_Response_Buffers_Assigner extends Assigner {
|
|
43
|
+
|
|
44
|
+
constructor(spec = {}) {
|
|
45
|
+
super(spec);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// assign to bundle....
|
|
49
|
+
// or array would be better.
|
|
50
|
+
|
|
51
|
+
// assign to (bundle) items in array.
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
// These assign functions should (all probably) be async
|
|
55
|
+
|
|
56
|
+
async assign(arr_bundled_items) {
|
|
57
|
+
// go through them....
|
|
58
|
+
|
|
59
|
+
// Maybe check that the correct items are in the bundle.
|
|
60
|
+
|
|
61
|
+
// Perhaps check for 1 of each js, css, html
|
|
62
|
+
// And could use a specific other class to assign these.
|
|
63
|
+
|
|
64
|
+
// Should be OK to make classes for really specific things.
|
|
65
|
+
// At this part of the system / API, it's not necessary / important to limit complexity in that way.
|
|
66
|
+
|
|
67
|
+
// The goal is to provide a very simple high level interface. Powerful too.
|
|
68
|
+
|
|
69
|
+
// Could assign a static_route property to the items in the bundles.
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
if (is_array(arr_bundled_items)) {
|
|
76
|
+
|
|
77
|
+
for (const item of arr_bundled_items) {
|
|
78
|
+
//console.log('item', item);
|
|
79
|
+
|
|
80
|
+
const {type} = item;
|
|
81
|
+
|
|
82
|
+
// And need to create the uncompressed response buffer.
|
|
83
|
+
|
|
84
|
+
// // response_buffers.identity I think....
|
|
85
|
+
|
|
86
|
+
if (item.text) {
|
|
87
|
+
|
|
88
|
+
// Async compression definitely seems much better here.
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
const buf_gzipped = await gzip_compress(item.response_buffers.identity);
|
|
92
|
+
|
|
93
|
+
item.response_buffers.gzip = buf_gzipped;
|
|
94
|
+
|
|
95
|
+
// Maybe should be 11 in many cases.
|
|
96
|
+
// Seems right when publishing static JS resources.???
|
|
97
|
+
// Compromise with 10 for the moment.
|
|
98
|
+
|
|
99
|
+
const buf_br = await br_compress(item.response_buffers.identity, {
|
|
100
|
+
params: {
|
|
101
|
+
//[zlib.constants.BROTLI_PARAM_MODE]: zlib.constants.BROTLI_MODE_TEXT,
|
|
102
|
+
[zlib.constants.BROTLI_PARAM_QUALITY]: 10,
|
|
103
|
+
[zlib.constants.BROTLI_PARAM_SIZE_HINT]: item.response_buffers.identity.length,
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
item.response_buffers.br = buf_br;
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
// The gzip response
|
|
111
|
+
// The brotli response
|
|
112
|
+
|
|
113
|
+
// promisifying these calls would help.
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
/*
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
const buf_identity_response = Buffer.from(item.text, 'utf-8');
|
|
120
|
+
|
|
121
|
+
item.response_buffers = item.response_buffers || {};
|
|
122
|
+
item.response_buffers.identity = buf_identity_response;
|
|
123
|
+
*/
|
|
124
|
+
} else {
|
|
125
|
+
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
//console.trace();
|
|
131
|
+
//throw 'stop';
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
} else {
|
|
135
|
+
console.trace();
|
|
136
|
+
throw 'stop';
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
module.exports = Single_Control_Webpage_Server_Static_Compressed_Response_Buffers_Assigner;
|
|
149
|
+
|
|
150
|
+
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
const Assigner = require('../Assigner');
|
|
4
|
+
|
|
5
|
+
const {is_array, each} = require('lang-tools');
|
|
6
|
+
|
|
7
|
+
// And will have some very or less specific assigners for some other things.
|
|
8
|
+
// Like the compressed (text?) response headers.
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Single_Control_Webpage_Server_Static_Headers_Assigner extends Assigner {
|
|
14
|
+
|
|
15
|
+
constructor(spec = {}) {
|
|
16
|
+
super(spec);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// assign to bundle....
|
|
20
|
+
// or array would be better.
|
|
21
|
+
|
|
22
|
+
// assign to (bundle) items in array.
|
|
23
|
+
|
|
24
|
+
async assign(arr_bundled_items) {
|
|
25
|
+
// go through them....
|
|
26
|
+
|
|
27
|
+
// Maybe check that the correct items are in the bundle.
|
|
28
|
+
|
|
29
|
+
// Perhaps check for 1 of each js, css, html
|
|
30
|
+
// And could use a specific other class to assign these.
|
|
31
|
+
|
|
32
|
+
// Should be OK to make classes for really specific things.
|
|
33
|
+
// At this part of the system / API, it's not necessary / important to limit complexity in that way.
|
|
34
|
+
|
|
35
|
+
// The goal is to provide a very simple high level interface. Powerful too.
|
|
36
|
+
|
|
37
|
+
// Could assign a static_route property to the items in the bundles.
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
if (is_array(arr_bundled_items)) {
|
|
41
|
+
|
|
42
|
+
for (const item of arr_bundled_items) {
|
|
43
|
+
//console.log('item', item);
|
|
44
|
+
|
|
45
|
+
item.response_headers = item.response_headers || {};
|
|
46
|
+
|
|
47
|
+
let str_content_type;
|
|
48
|
+
|
|
49
|
+
if (item.type === 'JavaScript') {
|
|
50
|
+
str_content_type = 'text/javascript; charset=utf-8';
|
|
51
|
+
} else if (item.type === 'CSS') {
|
|
52
|
+
str_content_type = 'text/css; charset=utf-8';
|
|
53
|
+
} else if (item.type === 'HTML') {
|
|
54
|
+
str_content_type = 'text/html; charset=utf-8';
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
// Different headers depending on the returned (ie accepted) content encoding types.
|
|
60
|
+
|
|
61
|
+
// item.response_buffers.identity / gzip / br
|
|
62
|
+
|
|
63
|
+
// go through the item.response_buffers
|
|
64
|
+
|
|
65
|
+
each(item.response_buffers, (buf, content_encoding_name) => {
|
|
66
|
+
|
|
67
|
+
//console.log('content_encoding_name', content_encoding_name);
|
|
68
|
+
|
|
69
|
+
const headers_for_content_encoding = item.response_headers[content_encoding_name] = item.response_headers[content_encoding_name] || {};
|
|
70
|
+
headers_for_content_encoding['Content-Length'] = buf.length;
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
if (str_content_type) {
|
|
74
|
+
headers_for_content_encoding['Content-Type'] = str_content_type;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (content_encoding_name === 'identity') {
|
|
78
|
+
|
|
79
|
+
} else {
|
|
80
|
+
headers_for_content_encoding['Content-Encoding'] = content_encoding_name;
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// And setting the content types too...
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
//console.trace();
|
|
93
|
+
//throw 'stop';
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
} else {
|
|
97
|
+
console.trace();
|
|
98
|
+
throw 'stop';
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
module.exports = Single_Control_Webpage_Server_Static_Headers_Assigner;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
const Assigner = require('../Assigner');
|
|
4
|
+
|
|
5
|
+
const {is_array} = require('lang-tools');
|
|
6
|
+
|
|
7
|
+
// And will have some very or less specific assigners for some other things.
|
|
8
|
+
// Like the compressed (text?) response headers.
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Single_Control_Webpage_Server_Static_Routes_Assigner extends Assigner {
|
|
14
|
+
|
|
15
|
+
constructor(spec = {}) {
|
|
16
|
+
super(spec);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// assign to bundle....
|
|
20
|
+
// or array would be better.
|
|
21
|
+
|
|
22
|
+
// assign to (bundle) items in array.
|
|
23
|
+
|
|
24
|
+
async assign(arr_bundled_items) {
|
|
25
|
+
// go through them....
|
|
26
|
+
|
|
27
|
+
// Maybe check that the correct items are in the bundle.
|
|
28
|
+
|
|
29
|
+
// Perhaps check for 1 of each js, css, html
|
|
30
|
+
// And could use a specific other class to assign these.
|
|
31
|
+
|
|
32
|
+
// Should be OK to make classes for really specific things.
|
|
33
|
+
// At this part of the system / API, it's not necessary / important to limit complexity in that way.
|
|
34
|
+
|
|
35
|
+
// The goal is to provide a very simple high level interface. Powerful too.
|
|
36
|
+
|
|
37
|
+
// Could assign a static_route property to the items in the bundles.
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
if (is_array(arr_bundled_items)) {
|
|
44
|
+
|
|
45
|
+
for (const item of arr_bundled_items) {
|
|
46
|
+
//console.log('item', item);
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
const {type} = item;
|
|
51
|
+
|
|
52
|
+
// Just very simple for the moment.
|
|
53
|
+
// Maybe will read it from the Ctrl?
|
|
54
|
+
// Better to have some kind of Standard_Resource_Path_Assignment_System
|
|
55
|
+
|
|
56
|
+
if (type === 'JavaScript') {
|
|
57
|
+
item.route = '/js/js.js';
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
} else if (type === 'CSS') {
|
|
62
|
+
item.route = '/css/css.css';
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
} else if (type === 'HTML') {
|
|
67
|
+
item.route = '/';
|
|
68
|
+
|
|
69
|
+
} else {
|
|
70
|
+
console.trace();
|
|
71
|
+
throw 'NYI - type: ' + type;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
//console.trace();
|
|
75
|
+
//throw 'stop';
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
} else {
|
|
79
|
+
console.trace();
|
|
80
|
+
throw 'stop';
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
module.exports = Single_Control_Webpage_Server_Static_Routes_Assigner;
|