jsgui3-server 0.0.121 → 0.0.122
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/.vscode/settings.json +6 -0
- package/README.md +10 -10
- package/controls/Active_HTML_Document.js +116 -116
- package/controls/README.md +7 -7
- package/controls/page/admin.js +74 -74
- package/controls/panel/admin.js +11 -11
- package/examples/_css/basic.css +913 -913
- package/examples/_css/database-control.css +51 -51
- package/examples/_css/jsgui.css +66 -66
- package/examples/_css/multi-layout.css +23 -23
- package/examples/_css/style.css +1669 -1669
- package/examples/_css/top-and-bottom-bars.css +54 -54
- package/examples/box/1) square box/client.js +188 -188
- package/examples/box/1) square box/server.js +112 -112
- package/examples/box/2) twenty square boxes/css flex wrap/client.js +248 -248
- package/examples/box/2) twenty square boxes/css flex wrap/server.js +112 -112
- package/examples/boxes/square_boxes.js +45 -48
- package/examples/boxes/square_boxes_client.js +132 -136
- package/examples/client-side-popup-menu-button.html +93 -93
- package/examples/color_palette.js +51 -51
- package/examples/color_palette_client.js +95 -95
- package/examples/controls/1) window/client.js +186 -186
- package/examples/controls/1) window/server.js +117 -117
- package/examples/controls/10) window, mirrored text inputs/client.js +320 -320
- package/examples/controls/10) window, mirrored text inputs/server.js +117 -117
- package/examples/controls/11) window, mirrored text fields/client.js +493 -251
- package/examples/controls/11) window, mirrored text fields/server.js +117 -117
- package/examples/controls/11b) window, shared Data_Object model mirrored text fields/client.js +613 -331
- package/examples/controls/11b) window, shared Data_Object model mirrored text fields/server.js +117 -117
- package/examples/controls/11c) window, shared Data_Value model mirrored text fields/client.js +617 -617
- package/examples/controls/11c) window, shared Data_Value model mirrored text fields/server.js +117 -117
- package/examples/controls/11d) window, shared model mirrored integer text fields/client.js +611 -280
- package/examples/controls/11d) window, shared model mirrored integer text fields/server.js +134 -22
- package/examples/controls/12) window, Select_Options control/client.js +435 -452
- package/examples/controls/12) window, Select_Options control/server.js +117 -117
- package/examples/controls/2) two windows/client.js +193 -193
- package/examples/controls/2) two windows/server.js +113 -113
- package/examples/controls/3) five windows/client.js +217 -217
- package/examples/controls/3) five windows/server.js +116 -115
- package/examples/controls/4) window, tabbed panel/client.js +54 -225
- package/examples/controls/4) window, tabbed panel/server.js +17 -117
- package/examples/controls/5) window, grid/client.js +204 -484
- package/examples/controls/5) window, grid/server.js +117 -119
- package/examples/controls/6) window, color_palette/client.js +204 -204
- package/examples/controls/6) window, color_palette/server.js +117 -117
- package/examples/controls/7) window, month_view/client.js +40 -231
- package/examples/controls/7) window, month_view/server.js +117 -117
- package/examples/controls/8) window, checkbox/client.js +247 -209
- package/examples/controls/8) window, checkbox/server.js +117 -117
- package/examples/controls/9) window, date picker/client.js +303 -303
- package/examples/controls/9) window, date picker/server.js +117 -117
- package/examples/controls/9b) window, shared data.model mirrored date pickers/client.js +398 -398
- package/examples/controls/9b) window, shared data.model mirrored date pickers/server.js +117 -117
- package/examples/controls/__old/_html-server-color-palette.js +114 -114
- package/examples/controls/__old/html-server-combo-box.js +104 -104
- package/examples/controls/__old/html-server-list.js +98 -98
- package/examples/controls/__old/html-server-popup-menu-button.js +114 -114
- package/examples/controls/__old/html-server-start-stop-toggle-button.js +146 -146
- package/examples/controls/__old/scs-arrow-button.js +36 -36
- package/examples/controls/__old/scs-date-picker.js +157 -157
- package/examples/controls/__old/scs-file-browser.js +82 -82
- package/examples/controls/__old/scs-item.js +159 -159
- package/examples/controls/__old/scs-month-arrow-selector.js +126 -126
- package/examples/controls/__old/scs-month-view.js +94 -94
- package/examples/controls/__old/scs-start-stop-toggle-button.js +40 -40
- package/examples/controls/__old/scs-tree.js +49 -49
- package/examples/controls/__old/scs-year-arrow-selector.js +127 -127
- package/examples/demos/date-picker.js +119 -119
- package/examples/demos/explain-encapsulation.js +9 -9
- package/examples/demos/resizing.js +35 -35
- package/examples/demos/server_time.js +6 -6
- package/examples/grids/grid_1.js +45 -45
- package/examples/grids/grid_1_client.js +329 -329
- package/examples/html-rendering.js +20 -20
- package/examples/html-server.js +105 -105
- package/examples/introducing jsgui3/server.js +110 -110
- package/examples/mx_display/mx_display_1.js +45 -45
- package/examples/mx_display/mx_display_1_client.js +444 -444
- package/fs2.js +1836 -1836
- package/http/responders/HTTP_Responder.js +15 -15
- package/http/responders/static/Static_Route_HTTP_Responder.js +105 -105
- package/module.js +34 -34
- package/old/_single-control-server.js +418 -418
- package/old/single-control-server.js +368 -368
- package/old/single-page-app.js +131 -131
- package/package.json +42 -42
- package/page-context.js +92 -92
- package/publishers/helpers/assigners/Assigner.js +10 -10
- package/publishers/helpers/assigners/static-compressed-response-buffers/Single_Control_Webpage_Server_Static_Compressed_Response_Buffers_Assigner.js +150 -150
- package/publishers/helpers/assigners/static-headers/Single_Control_Webpage_Server_Static_Headers_Assigner.js +109 -109
- package/publishers/helpers/assigners/static-routes/Single_Control_Webpage_Server_Static_Routes_Assigner.js +91 -91
- package/publishers/helpers/assigners/static-uncompressed-response-buffers/Single_Control_Webpage_Server_Static_Uncompressed_Response_Buffers_Assigner.js +104 -104
- package/publishers/helpers/preparers/static/bundle/Ready_To_Serve_Preparer.js +18 -18
- package/publishers/helpers/preparers/static/bundle/Static_Routes_Responses_Webpage_Bundle_Preparer.js +44 -44
- package/publishers/http-function-publisher.js +212 -212
- package/publishers/http-html-page-publisher.js +5 -5
- package/publishers/http-html-publisher.js +24 -24
- package/publishers/http-js-publisher.js +135 -135
- package/publishers/http-observable-publisher.js +124 -124
- package/publishers/http-publisher.js +53 -53
- package/publishers/http-resource-publisher.js +325 -325
- package/publishers/http-webpage-publisher.js +659 -658
- package/publishers/http-webpageorsite-publisher.js +343 -343
- package/publishers/http-website-publisher.js +640 -640
- package/publishers/notes.md +9 -9
- package/resources/README.md +16 -16
- package/resources/_old_website-javascript-resource.js +994 -994
- package/resources/_old_website-resource.js +507 -507
- package/resources/compile/server-resource-compilation.js +43 -43
- package/resources/data-resource.js +118 -118
- package/resources/fs-resource.js +146 -146
- package/resources/jsbuilder/Abstract_Single_Declaration.js +105 -105
- package/resources/jsbuilder/Abstract_Single_Declaration_Sequence.js +42 -42
- package/resources/jsbuilder/JS_AST/JS_AST_Abstract_Node.js +61 -61
- package/resources/jsbuilder/JS_AST/JS_AST_Abstract_Node_Group.js +41 -41
- package/resources/jsbuilder/JS_AST/JS_AST_Group_Shared.js +61 -61
- package/resources/jsbuilder/JS_AST/JS_AST_Node.js +93 -93
- package/resources/jsbuilder/JS_AST/JS_AST_Node_0-Core.js +253 -253
- package/resources/jsbuilder/JS_AST/JS_AST_Node_1-Babel.js +337 -337
- package/resources/jsbuilder/JS_AST/JS_AST_Node_10-Changing.js +39 -39
- package/resources/jsbuilder/JS_AST/JS_AST_Node_2.1.1-Child.js +96 -96
- package/resources/jsbuilder/JS_AST/JS_AST_Node_2.1.2-Parent.js +37 -37
- package/resources/jsbuilder/JS_AST/JS_AST_Node_2.1.3-Ancestor.js +61 -61
- package/resources/jsbuilder/JS_AST/JS_AST_Node_2.2-Inner.js +43 -43
- package/resources/jsbuilder/JS_AST/JS_AST_Node_2.3-All.js +72 -72
- package/resources/jsbuilder/JS_AST/JS_AST_Node_2.4-Sibling.js +92 -92
- package/resources/jsbuilder/JS_AST/JS_AST_Node_2.5-Available_In_Scope.js +29 -29
- package/resources/jsbuilder/JS_AST/JS_AST_Node_2.9-Signature.js +116 -116
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3-Basics.js +159 -159
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.0.0-Basics_First.js +178 -178
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.0.1-Basics_Second.js +87 -87
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.0.99-Basics_Last.js +91 -91
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.1-Basics_Each.js +136 -136
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.1.5-Basics_Count.js +73 -73
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.2-Basics_Filter.js +39 -39
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.3-Basics_Collect.js +85 -85
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.4-Basics_Select.js +42 -42
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.5-Basics_Find.js +40 -40
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.6-Basics_Callmap.js +54 -54
- package/resources/jsbuilder/JS_AST/JS_AST_Node_4.0-Index_Indexes.js +45 -45
- package/resources/jsbuilder/JS_AST/JS_AST_Node_4.1-Index.js +343 -343
- package/resources/jsbuilder/JS_AST/JS_AST_Node_5.0-Category.js +38 -38
- package/resources/jsbuilder/JS_AST/JS_AST_Node_5.1-Category_Identifier.js +30 -30
- package/resources/jsbuilder/JS_AST/JS_AST_Node_5.2-Category_Literal.js +28 -28
- package/resources/jsbuilder/JS_AST/JS_AST_Node_5.3-Category_Expression.js +26 -26
- package/resources/jsbuilder/JS_AST/JS_AST_Node_5.4-Category_Pattern.js +8 -8
- package/resources/jsbuilder/JS_AST/JS_AST_Node_5.5-Category_Declaration.js +43 -43
- package/resources/jsbuilder/JS_AST/JS_AST_Node_5.6-Category_Statement.js +21 -21
- package/resources/jsbuilder/JS_AST/JS_AST_Node_6.0-Type.js +89 -89
- package/resources/jsbuilder/JS_AST/JS_AST_Node_6.1-Type_Class_Declaration.js +8 -8
- package/resources/jsbuilder/JS_AST/JS_AST_Node_6.2-Type_Variable_Declaration.js +27 -27
- package/resources/jsbuilder/JS_AST/JS_AST_Node_6.3-Type_Variable_Declarator.js +28 -28
- package/resources/jsbuilder/JS_AST/JS_AST_Node_7-Query.js +736 -736
- package/resources/jsbuilder/JS_AST/JS_AST_Node_8-Features.js +64 -64
- package/resources/jsbuilder/JS_AST/JS_AST_Node_9-Planning.js +31 -31
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Arrangement.js +15 -15
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Node_Declared_Object.js +305 -305
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Node_Feature.js +77 -77
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Node_Feature_Declaration.js +248 -248
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Node_Feature_Declarator.js +138 -138
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/JS_AST_Root_Node_Feature.js +10 -10
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/JS_AST_Root_Node_Feature_Exported.js +100 -100
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/JS_AST_Root_Node_Feature_Exports.js +60 -60
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/JS_AST_Root_Node_Interpreted.js +179 -179
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/_JSGUI_Root_Node_Interpreted.js +43 -43
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/special_case_objectassign_to_object.js +12 -12
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Group.js +35 -35
- package/resources/jsbuilder/JS_AST/JS_AST_Operation.js +11 -11
- package/resources/jsbuilder/JS_AST/JS_AST_Operation_On_Relationship.js +31 -31
- package/resources/jsbuilder/JS_AST/JS_AST_Ordered_Relationship_Node_To_Group.js +37 -37
- package/resources/jsbuilder/JS_AST/JS_AST_Ordinal.js +39 -39
- package/resources/jsbuilder/JS_AST/JS_AST_Ordinal_Relationship.js +25 -25
- package/resources/jsbuilder/JS_AST/JS_AST_Relationship_Node_To_Group.js +200 -200
- package/resources/jsbuilder/JS_AST/JS_AST_Relationship_Node_Within_Group_To_Node.js +43 -43
- package/resources/jsbuilder/JS_AST/_JS_AST_Node_3.8-Query_Features.js +76 -76
- package/resources/jsbuilder/JS_AST/query/enable_array_as_queryable.js +227 -227
- package/resources/jsbuilder/JS_AST/query/find_object_keys.js +404 -404
- package/resources/jsbuilder/JS_AST/query/node_queries.js +8 -8
- package/resources/jsbuilder/JS_AST/query/root_query_identidy.js +11 -11
- package/resources/jsbuilder/JS_AST_Node_Extended/JSGUI_Singular_Declaration.js +85 -85
- package/resources/jsbuilder/JS_AST_Node_Extended/JS_AST_Node_Declaration.js +123 -123
- package/resources/jsbuilder/JS_AST_Node_Extended/JS_AST_Node_Extended.js +87 -87
- package/resources/jsbuilder/JS_AST_Node_Extended/JS_AST_Node_Extended_0-Core.js +10 -10
- package/resources/jsbuilder/JS_Builder.js +10 -10
- package/resources/jsbuilder/JS_File/Feature/JS_File_Declared_Object.js +31 -31
- package/resources/jsbuilder/JS_File/Feature/JS_File_Exported_Object_Info.js +25 -25
- package/resources/jsbuilder/JS_File/Feature/JS_File_Exports.js +78 -78
- package/resources/jsbuilder/JS_File/Feature/JS_File_Feature.js +17 -17
- package/resources/jsbuilder/JS_File/Feature/JS_File_Imported_Object_Info.js +25 -25
- package/resources/jsbuilder/JS_File/Feature/JS_File_Imports.js +8 -8
- package/resources/jsbuilder/JS_File/JS_File.js +12 -12
- package/resources/jsbuilder/JS_File/JS_File_0-Core.js +202 -202
- package/resources/jsbuilder/JS_File/JS_File_1-Early_Parse.js +175 -175
- package/resources/jsbuilder/JS_File/JS_File_2-Babel.js +81 -81
- package/resources/jsbuilder/JS_File/JS_File_3-JS_AST_Node.js +86 -86
- package/resources/jsbuilder/JS_File/JS_File_4-Query.js +413 -413
- package/resources/jsbuilder/JS_File/JS_File_4.1-Query_Features.js +414 -414
- package/resources/jsbuilder/JS_File/JS_File_5-Planning.js +59 -59
- package/resources/jsbuilder/JS_File/JS_File_6-Changing.js +24 -24
- package/resources/jsbuilder/JS_File/JS_File_Export_Reference.js +12 -12
- package/resources/jsbuilder/JS_File/JS_File_Import_Reference.js +23 -23
- package/resources/jsbuilder/JS_File/JS_File_Import_References.js +31 -31
- package/resources/jsbuilder/JS_File/JS_File_Processor.js +16 -16
- package/resources/jsbuilder/JS_File/JS_Files.js +15 -15
- package/resources/jsbuilder/Module.js +14 -14
- package/resources/jsbuilder/Platform.js +13 -13
- package/resources/jsbuilder/Platforms.js +69 -69
- package/resources/jsbuilder/Project.js +109 -109
- package/resources/jsbuilder/Reference.js +1 -1
- package/resources/jsbuilder/Reference_Sequence.js +16 -16
- package/resources/jsbuilder/Scope.js +29 -29
- package/resources/jsbuilder/Variable_Name_Provider.js +42 -42
- package/resources/jsbuilder/_JS_File.js +225 -225
- package/resources/jsbuilder/ast_query.js +20 -20
- package/resources/jsbuilder/babel/babel_consts.js +162 -162
- package/resources/jsbuilder/babel/babel_node_tools.js +541 -541
- package/resources/jsbuilder/babel/deep_iterate/deep_iterate_babel.js +923 -904
- package/resources/jsbuilder/build.js +16 -16
- package/resources/jsbuilder/platform_notes.md +66 -66
- package/resources/jsbuilder/test/test_ast_node.js +381 -381
- package/resources/jsbuilder/test/test_js_file.js +303 -303
- package/resources/jsbuilder/test/test_project.js +157 -157
- package/resources/local-server-info-resource.js +96 -96
- package/resources/notes.txt +10 -10
- package/resources/old/website-image-resource.js +1185 -1185
- package/resources/process-js.js +498 -498
- package/resources/processors/bundlers/bundle.js +29 -29
- package/resources/processors/bundlers/bundler.js +23 -23
- package/resources/processors/bundlers/css-bundler.js +234 -234
- package/resources/processors/bundlers/js/JS_Bundler.js +51 -51
- package/resources/processors/bundlers/js/esbuild/Advanced_JS_Bundler_Using_ESBuild.js +388 -391
- package/resources/processors/bundlers/js/esbuild/Bundler_Using_ESBuild.js +8 -8
- package/resources/processors/bundlers/js/esbuild/Core_JS_Non_Minifying_Bundler_Using_ESBuild.js +188 -188
- package/resources/processors/bundlers/js/esbuild/Core_JS_Single_File_Minifying_Bundler_Using_ESBuild.js +191 -192
- package/resources/processors/bundlers/js/esbuild/_Old_CSS_Extractor.js +239 -239
- package/resources/processors/bundlers/js-bundler.js +263 -263
- package/resources/processors/bundlers/test_ast.js +73 -73
- package/resources/processors/bundlers/webpage-bundler.js +404 -404
- package/resources/processors/bundlers/website-bundler.js +22 -22
- package/resources/processors/extractors/Extractor.js +9 -11
- package/resources/processors/extractors/js/css_and_js/AST_Node/CSS_And_JS_From_JS_String_Using_AST_Node_Extractor.js +239 -254
- package/resources/processors/extractors/js/css_and_js/CSS_And_JS_From_JS_String_Extractor.js +3 -3
- package/resources/processors/extractors/string/Pos_Span_String_Extractor.js +93 -93
- package/resources/server-installed-tools.js +28 -28
- package/resources/server-resource-pool.js +41 -41
- package/resources/website-audio-resource.js +735 -735
- package/resources/website-css-resource.js +411 -411
- package/resources/website-image-resource.js +412 -412
- package/resources/website-javascript-resource-processor.js +908 -908
- package/resources/website-javascript-resource.js +874 -874
- package/resources/website-resource-processor.js +10 -10
- package/resources/website-resource.js +164 -164
- package/resources/website-static-html-resource.js +199 -199
- package/resources/website-template-html-resource.js +231 -231
- package/roadmap.md +75 -75
- package/server.js +609 -573
- package/static-page-context.js +13 -13
- package/website/webpage.js +81 -81
- package/website/website-group.js +15 -15
- package/website/website.js +260 -260
- package/examples/controls/11d) window, shared model mirrored integer text fields/both.js +0 -17
- package/examples/controls/13) window, shared model mirrored lat_long/client.js +0 -933
- package/examples/controls/13) window, shared model mirrored lat_long/server.js +0 -50
- package/examples/controls/14) window, control compositional model/client.js +0 -328
- package/examples/controls/14) window, control compositional model/server.js +0 -118
- package/examples/controls/14a) window, control spec has compositional model/client.js +0 -440
- package/examples/controls/14a) window, control spec has compositional model/server.js +0 -118
- package/examples/controls/15) window, text field/client.js +0 -256
- package/examples/controls/15) window, text field/server.js +0 -39
- package/examples/controls/16) Window([Text_Input])/client.js +0 -266
- package/examples/controls/16) Window([Text_Input])/server.js +0 -109
- package/examples/controls/16a) Window([Text_Input]) Integer data.model.data_type/client.js +0 -494
- package/examples/controls/16a) Window([Text_Input]) Integer data.model.data_type/isomorphic.js +0 -24
- package/examples/controls/16a) Window([Text_Input]) Integer data.model.data_type/server.js +0 -73
- package/examples/controls/2b) two window, context menus/client.js +0 -193
- package/examples/controls/2b) two window, context menus/server.js +0 -114
- package/examples/controls/4a) window, tabbed panel with various controls inside/client.js +0 -233
- package/examples/controls/4a) window, tabbed panel with various controls inside/server.js +0 -118
|
@@ -1,641 +1,641 @@
|
|
|
1
|
-
// A publisher handles HTTP requests.
|
|
2
|
-
|
|
3
|
-
// This is going to take over some of the responsibilities of the old website resource, which was unfocused code that was
|
|
4
|
-
// doing some of the main / most important parts of serving the website.
|
|
5
|
-
|
|
6
|
-
const {each, Router, tof} = require('jsgui3-html');
|
|
7
|
-
const HTTP_Publisher = require('./http-publisher');
|
|
8
|
-
const {obs} = require('fnl');
|
|
9
|
-
|
|
10
|
-
// The Webpage bundler should be able to come up with the compiled JS and CSS, maybe even a favicon.
|
|
11
|
-
|
|
12
|
-
// HTTP_Webpageorsite_Publisher
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const Website = require('jsgui3-website');
|
|
17
|
-
|
|
18
|
-
const Webpage_Bundler = require('../resources/processors/bundlers/webpage-bundler');
|
|
19
|
-
const Bundle = require('../resources/processors/bundlers/bundle');
|
|
20
|
-
|
|
21
|
-
// Now it's the very basics of a website publisher. Quite flexible but could do with more.
|
|
22
|
-
// Better integration with bundler
|
|
23
|
-
// Rendering webpages that are dynamic and therefore not bundled (eg user specific content).
|
|
24
|
-
// Though the js could be bundled. Maybe some of the controls could be bundled? Or semi-bundled?
|
|
25
|
-
|
|
26
|
-
// HTTP_Webpage_Publisher could be interesting.
|
|
27
|
-
// The Website Publisher could make use of some of its functionality.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
// Handling HTTP / bundling for a specific page could be cool.
|
|
31
|
-
|
|
32
|
-
// A Webpage Publisher may be simpler and better to work on in the short term.
|
|
33
|
-
// Maybe would not need to be (as) concerned with routing.
|
|
34
|
-
// Could be useful for publishing a SPA of course, kind of a website but as a single page.
|
|
35
|
-
|
|
36
|
-
// This seems more like the server router these days
|
|
37
|
-
// The main server router seems to pass everything to this - maybe that will change.
|
|
38
|
-
|
|
39
|
-
// Maybe give it some kind of Website_Server????
|
|
40
|
-
|
|
41
|
-
// Have the Website_Server use the Website_Publisher????
|
|
42
|
-
|
|
43
|
-
// Need to somewhat separate concerns.
|
|
44
|
-
|
|
45
|
-
// Publisher here could be simple in terms of bundling, and then giving the paths to the router.
|
|
46
|
-
// And could have really simple code implementation of doing just that.
|
|
47
|
-
|
|
48
|
-
// This basically can be simple....
|
|
49
|
-
// But make the classes' structures more complicated where necessary to accommodate.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
// Could be just a few lines of logic probably, at least the simplest core implementation.
|
|
53
|
-
|
|
54
|
-
// Think the server or the website already has a router, so have the website resource's router do the routing.
|
|
55
|
-
// Maybe upgrade the routers to handle premade (compressed) responses.
|
|
56
|
-
|
|
57
|
-
// Maybe better to bundle and publish resources.
|
|
58
|
-
// resource-processors in its own dir?
|
|
59
|
-
// as in it's not actually part of resources?
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
// Need to basically make this do very little.
|
|
65
|
-
|
|
66
|
-
// Publish (website, server_router)
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
// Or publish it only under some URLs / domains....?
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
// Probably is worth by default having it use the HTTP_Website_Publisher with really simple server setups.
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
// Extend HTTP_Web_Item_Publisher HTTP_Web_Page_Or_Site_Publisher (synonym) ????
|
|
80
|
-
|
|
81
|
-
// Share functionality between webpage and website where useful.
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const HTTP_Webpageorsite_Publisher = require('./http-webpageorsite-publisher');
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
class HTTP_Website_Publisher extends HTTP_Webpageorsite_Publisher {
|
|
89
|
-
// Website generally serves JS from a single address.
|
|
90
|
-
// Webpage could have its specific JS.
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
// Maybe the Publisher should not have its own router?
|
|
94
|
-
// But it provides items with paths from bundles it gets made to the website server's router.
|
|
95
|
-
|
|
96
|
-
// Def looks like its worth rearchitecturing this to provide more consistency on the lower level, and a 'just works' simplicity
|
|
97
|
-
// on the higher level.
|
|
98
|
-
|
|
99
|
-
// Plus some base classes that themselves don't do all that much, and then subclasses of them that do things in specific
|
|
100
|
-
// ways, so that implementations of specific parts are interchangable.
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
constructor(spec = {}) {
|
|
107
|
-
super(spec)
|
|
108
|
-
// A website property.
|
|
109
|
-
|
|
110
|
-
//console.trace();
|
|
111
|
-
//throw 'stop';
|
|
112
|
-
|
|
113
|
-
// spec webpage????
|
|
114
|
-
|
|
115
|
-
let website;
|
|
116
|
-
if (spec.website) {
|
|
117
|
-
if (spec.website instanceof Website) {
|
|
118
|
-
website = spec.website;
|
|
119
|
-
} else {
|
|
120
|
-
console.trace();
|
|
121
|
-
throw 'Expected spec.website to be of type "jsgui3-website" class instance';
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
Object.defineProperty(this, 'website', {
|
|
125
|
-
get() {
|
|
126
|
-
return website;
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
// A get_ready function for every level of the class for web publishing may help.
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
// The publisher should not have a router (for the moment???)
|
|
138
|
-
// It should however determine routes, and provide them to the router.
|
|
139
|
-
|
|
140
|
-
// Creating a Published_Website object perhaps.
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
/*
|
|
144
|
-
|
|
145
|
-
let router = new Router();
|
|
146
|
-
Object.defineProperty(this, 'router', {
|
|
147
|
-
get() {
|
|
148
|
-
return router;
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
*/
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
// Disk path client js being a property of the website itself?
|
|
160
|
-
// Critical overall functionality, dont want to remove it from here for the moment. See if not critical here.
|
|
161
|
-
|
|
162
|
-
/*
|
|
163
|
-
|
|
164
|
-
let disk_path_client_js;
|
|
165
|
-
if (spec.disk_path_client_js) disk_path_client_js = spec.disk_path_client_js;
|
|
166
|
-
Object.defineProperty(this, 'disk_path_client_js', {
|
|
167
|
-
get() {
|
|
168
|
-
return disk_path_client_js;
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
*/
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
// And this could be an observable too.
|
|
177
|
-
// May get admin pages working on a slightly lower level.
|
|
178
|
-
// Makes sense as they are for administering other pages (mostly).
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
//console.log('http-website-publisher disk_path_client_js', disk_path_client_js);
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
//throw 'stop';
|
|
186
|
-
// This could be an observable that acts sequentially and async.
|
|
187
|
-
|
|
188
|
-
// See about moving specific complexity elsewhere....
|
|
189
|
-
// See if what the website publisher does can be summed up expressively in JS.
|
|
190
|
-
|
|
191
|
-
// Uses a builder / packager on the website.
|
|
192
|
-
// Keeps track of a little bit of data on what's been published (could have an observable status event)
|
|
193
|
-
// Tells the server to publish it (on specified URL / Route - specified where? Defaults? Interchangable systems of default URLS paths?)
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
// But make this async (obs as well?)
|
|
197
|
-
// Have a sequence of events that takes place.
|
|
198
|
-
// Use the correct specific classes to do the correct specific things.
|
|
199
|
-
// Then make sure the implementations are correct.
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
// Will probably insert new bundling code here - but refer to advanced classes that handle the details.
|
|
209
|
-
|
|
210
|
-
console.log('\n\nskipping __old__setup_website_publishing');
|
|
211
|
-
console.trace();
|
|
212
|
-
console.log('\n\n');
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
const __old__setup_website_publishing = (website) => {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
// Split up the bundling and response serving responsibilities.
|
|
219
|
-
// Should put it through the router (more as normal) when published.
|
|
220
|
-
// Maybe I'll need another 100 classes for this to work, maybe not, but should make everything explicit, but also concise,
|
|
221
|
-
// and then work on abbreviations and (unambiguous) shorthands.
|
|
222
|
-
// Or even settings for what the (default) shorthands do.
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
// Bundle it - Get some package(bundle) of pages.
|
|
226
|
-
|
|
227
|
-
// Website_Bundle perhaps...?
|
|
228
|
-
// All the static assets put together.
|
|
229
|
-
// Pages that don't have dynamic content are pre-rendered and compressed.
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
// 1) Bundle
|
|
236
|
-
// 2) Publish that bundle
|
|
237
|
-
// 2a) Provide the router with all the necessary URLs and (compressed) pregenerated responses from that bundle.
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
// Website_Bundle_Publisher perhaps....?
|
|
241
|
-
|
|
242
|
-
// Def seems worth it to refactor it into still more complicated classes, but to aim for really simple and concise code within
|
|
243
|
-
// those classes, at least when it comes to a simple and intuitive API that represents what is going on.
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
//console.log('website', website);
|
|
262
|
-
//console.log('website.pages', website.pages);
|
|
263
|
-
//console.log('website.pages.length()', website.pages.length());
|
|
264
|
-
//throw 'stop';
|
|
265
|
-
|
|
266
|
-
// This is currently really inflexible for a website with multiple pages.
|
|
267
|
-
// Pages could be given names.
|
|
268
|
-
// Don't want to be too prescriptive here, but do want to get this bundling and working.
|
|
269
|
-
|
|
270
|
-
// Do want to get it right in theory and in structure for a variety of possibilities.
|
|
271
|
-
|
|
272
|
-
// Should pay more attention to setting up the headers on the responses.
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
// should the website have a 'main' or 'front' or 'first' page, with it having its HTML rendered?
|
|
281
|
-
return obs((next, complete, error) => {
|
|
282
|
-
(async () => {
|
|
283
|
-
// not iterating properly through the collection without ._arr.
|
|
284
|
-
// May make more sense to have 2 versions,
|
|
285
|
-
// for 1 page
|
|
286
|
-
// for 2+ pages
|
|
287
|
-
const opts_bundling = {};
|
|
288
|
-
if (disk_path_client_js) opts_bundling.disk_path_client_js = disk_path_client_js;
|
|
289
|
-
|
|
290
|
-
if (website.pages._arr.length === 0) {
|
|
291
|
-
throw 'NYI';
|
|
292
|
-
} else if (website.pages._arr.length === 1) {
|
|
293
|
-
const page = website.pages._arr[0];
|
|
294
|
-
const obs_bundling = Webpage_Bundler.bundle_web_page(page, opts_bundling);
|
|
295
|
-
//console.log('doing bundling');
|
|
296
|
-
//console.log('obs_bundling', obs_bundling);
|
|
297
|
-
//throw 'stop';
|
|
298
|
-
obs_bundling.on('complete', obs_bundling_res => {
|
|
299
|
-
// Should be a Bundle rather than a Buffer?
|
|
300
|
-
console.log('obs_bundling res', obs_bundling_res);
|
|
301
|
-
// Need to have the HTML rendering and HTTP serving here as well.
|
|
302
|
-
//const page_bundle = res;
|
|
303
|
-
if (obs_bundling_res instanceof Bundle) {
|
|
304
|
-
//console.log('1) obs_bundling_res._arr.length', obs_bundling_res._arr.length);
|
|
305
|
-
// then need to handle the page construction and routing of http requests.
|
|
306
|
-
console.log('obs_bundling_res._arr.length', obs_bundling_res._arr.length);
|
|
307
|
-
each(obs_bundling_res, item => {
|
|
308
|
-
//console.log('item', item);
|
|
309
|
-
//console.log('item.path', item.path, item['content-type']);
|
|
310
|
-
if (item['content-type']) {
|
|
311
|
-
const ct = item['content-type'];
|
|
312
|
-
if (ct === 'text/html') {
|
|
313
|
-
const http_serve_html = (req, res) => {
|
|
314
|
-
res.writeHead(200, {
|
|
315
|
-
'Content-Type': 'text/html'
|
|
316
|
-
});
|
|
317
|
-
res.end(item.value, 'utf-8');
|
|
318
|
-
}
|
|
319
|
-
router.set_route(item.path, (req, res) => {
|
|
320
|
-
http_serve_html(req, res);
|
|
321
|
-
});
|
|
322
|
-
} else {
|
|
323
|
-
const http_serve_any = (req, res) => {
|
|
324
|
-
res.writeHead(200, {
|
|
325
|
-
'Content-Type': ct
|
|
326
|
-
});
|
|
327
|
-
res.end(item.value, 'utf-8');
|
|
328
|
-
}
|
|
329
|
-
router.set_route(item.path, (req, res) => {
|
|
330
|
-
http_serve_any(req, res);
|
|
331
|
-
});
|
|
332
|
-
//throw 'NYI';
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
} else {
|
|
336
|
-
throw 'NYI';
|
|
337
|
-
}
|
|
338
|
-
})
|
|
339
|
-
|
|
340
|
-
//console.trace();
|
|
341
|
-
//throw 'stop';
|
|
342
|
-
complete(obs_bundling_res);
|
|
343
|
-
} else {
|
|
344
|
-
|
|
345
|
-
console.log('tof(obs_bundling_res)', tof(obs_bundling_res));
|
|
346
|
-
|
|
347
|
-
console.trace();
|
|
348
|
-
throw 'stop';
|
|
349
|
-
}
|
|
350
|
-
});
|
|
351
|
-
} else if (website.pages._arr.length > 1) {
|
|
352
|
-
throw 'NYI';
|
|
353
|
-
for (const page in website.pages._arr) {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
// With multiple pages, add page to bundle.
|
|
358
|
-
|
|
359
|
-
const obs_bundling = Webpage_Bundler.bundle_web_page(page, opts_bundling);
|
|
360
|
-
//console.log('doing bundling');
|
|
361
|
-
//console.log('obs_bundling', obs_bundling);
|
|
362
|
-
|
|
363
|
-
//throw 'stop';
|
|
364
|
-
|
|
365
|
-
obs_bundling.on('complete', res => {
|
|
366
|
-
//console.log('obs_bundling res', res);
|
|
367
|
-
const page_bundle = res;
|
|
368
|
-
|
|
369
|
-
console.log('page_bundle._arr.length', page_bundle._arr.length);
|
|
370
|
-
|
|
371
|
-
//complete(bundle);
|
|
372
|
-
|
|
373
|
-
});
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
const old = () => {
|
|
377
|
-
obs_bundling.on('complete', res => {
|
|
378
|
-
//console.log('obs_bundling res', res);
|
|
379
|
-
const bundle = res;
|
|
380
|
-
//console.log('bundle._arr.length', bundle._arr.length);
|
|
381
|
-
//console.log('Object.keys(bundle)', Object.keys(bundle));
|
|
382
|
-
|
|
383
|
-
if (bundle._arr.length === 1) {
|
|
384
|
-
// And check it's HTML inside...?
|
|
385
|
-
|
|
386
|
-
const bundled_item = bundle._arr[0];
|
|
387
|
-
//console.log('bundled_item', bundled_item);
|
|
388
|
-
|
|
389
|
-
if (bundled_item['content-type']) {
|
|
390
|
-
const ct = bundled_item['content-type'];
|
|
391
|
-
if (ct === 'text/html') {
|
|
392
|
-
const http_serve_html = (req, res) => {
|
|
393
|
-
res.writeHead(200, {
|
|
394
|
-
'Content-Type': 'text/html'
|
|
395
|
-
});
|
|
396
|
-
res.end(bundled_item.value, 'utf-8');
|
|
397
|
-
}
|
|
398
|
-
router.set_route(bundled_item.path, (req, res) => {
|
|
399
|
-
http_serve_html(req, res);
|
|
400
|
-
});
|
|
401
|
-
} else {
|
|
402
|
-
throw 'NYI';
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
} else {
|
|
406
|
-
throw 'NYI';
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
// need to create / use the handler for it here.
|
|
410
|
-
// will have various http handler functions to reference and use.
|
|
411
|
-
// will have details of http handling in other files.
|
|
412
|
-
|
|
413
|
-
// Maybe use an HTML publisher for this? (if it's HTML).
|
|
414
|
-
// Or publisher by mime type (lookup).
|
|
415
|
-
|
|
416
|
-
// create http handler function....
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
} else {
|
|
421
|
-
|
|
422
|
-
// Multiple items at multiple paths....
|
|
423
|
-
|
|
424
|
-
each(bundle, item => {
|
|
425
|
-
//console.log('item', item);
|
|
426
|
-
//console.log('item.path', item.path, item['content-type']);
|
|
427
|
-
|
|
428
|
-
if (item['content-type']) {
|
|
429
|
-
const ct = item['content-type'];
|
|
430
|
-
if (ct === 'text/html') {
|
|
431
|
-
const http_serve_html = (req, res) => {
|
|
432
|
-
res.writeHead(200, {
|
|
433
|
-
'Content-Type': 'text/html'
|
|
434
|
-
});
|
|
435
|
-
res.end(item.value, 'utf-8');
|
|
436
|
-
}
|
|
437
|
-
router.set_route(item.path, (req, res) => {
|
|
438
|
-
http_serve_html(req, res);
|
|
439
|
-
});
|
|
440
|
-
} else {
|
|
441
|
-
const http_serve_any = (req, res) => {
|
|
442
|
-
res.writeHead(200, {
|
|
443
|
-
'Content-Type': ct
|
|
444
|
-
});
|
|
445
|
-
res.end(item.value, 'utf-8');
|
|
446
|
-
}
|
|
447
|
-
router.set_route(item.path, (req, res) => {
|
|
448
|
-
http_serve_any(req, res);
|
|
449
|
-
});
|
|
450
|
-
|
|
451
|
-
//throw 'NYI';
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
} else {
|
|
455
|
-
throw 'NYI';
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
})
|
|
459
|
-
|
|
460
|
-
//console.trace();
|
|
461
|
-
//throw 'NYI';
|
|
462
|
-
}
|
|
463
|
-
})
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
//console.log(`${property}: ${object[property]}`);
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
})().catch(err => {
|
|
475
|
-
console.error(err);
|
|
476
|
-
});
|
|
477
|
-
});
|
|
478
|
-
// put pages into a router here...
|
|
479
|
-
// however, may need to be on the lookout for other content that needs to be bundled with each page in the site.
|
|
480
|
-
|
|
481
|
-
// Now let's try bundling an active JS client.
|
|
482
|
-
// May need to compile / render JSGUI Controls to HTML / full HTML pages.
|
|
483
|
-
|
|
484
|
-
// And unspecified pages such as admin pages?
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
//throw 'NYI';
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
if (website) {
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
console.trace();
|
|
495
|
-
|
|
496
|
-
throw 'NYI - HTTP_Website_Publisher needs to publish specified website';
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
// Website_Bundle class would help.
|
|
500
|
-
|
|
501
|
-
// jsgui3-website-bundle.
|
|
502
|
-
// Could make a separate module for it, give it a very simple API.
|
|
503
|
-
// Probably would only want to bundle websites on the server though.
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
// Prepare website for publishing
|
|
514
|
-
// Prepare being building static resources, making a list of the static routes / page content to serve.
|
|
515
|
-
// Static_Route_Content clases somewhere too.
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
// Use many different class names to help keep track of what the objects do, and allow for flexibility.
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
// Then the type of the website....
|
|
523
|
-
// Do make use of runtime polymorphism and type checking.
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
/*
|
|
534
|
-
|
|
535
|
-
const obs_setup = setup_website_publishing(website);
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
obs_setup.on('complete', res_complete => {
|
|
539
|
-
console.log('setup complete');
|
|
540
|
-
this.raise('ready');
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
})
|
|
544
|
-
|
|
545
|
-
*/
|
|
546
|
-
} else {
|
|
547
|
-
|
|
548
|
-
// Do the async get_ready function....
|
|
549
|
-
|
|
550
|
-
(async() => {
|
|
551
|
-
|
|
552
|
-
await this.get_ready();
|
|
553
|
-
this.raise('ready');
|
|
554
|
-
|
|
555
|
-
})();
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
//
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
// Create a router for the website if it does not already have one.
|
|
562
|
-
// Or maybe not....
|
|
563
|
-
|
|
564
|
-
// Do we already know all of the pages in the website?
|
|
565
|
-
// Maybe there are dynamic pages.
|
|
566
|
-
|
|
567
|
-
// Probably best to come up with a bundle here, or at an early stage.
|
|
568
|
-
|
|
569
|
-
// .prepare_bundle?
|
|
570
|
-
|
|
571
|
-
// .bundle?
|
|
572
|
-
// seems clearest that we will be getting / preparing multiple files.
|
|
573
|
-
|
|
574
|
-
// Bundling and compiling web content seems like a better thing to get working before serving (or attempting to serve) it.
|
|
575
|
-
// .build?
|
|
576
|
-
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
async get_ready() {
|
|
580
|
-
await super.get_ready();
|
|
581
|
-
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
handle_http(req, res) {
|
|
586
|
-
// Because it's already been set up in the router! It should have been.
|
|
587
|
-
return this.router.process(req, res);
|
|
588
|
-
|
|
589
|
-
// Called from a different context? Doubt we want that.
|
|
590
|
-
// Now called strangely, without context.
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
// The router does it all...???
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
/*
|
|
597
|
-
|
|
598
|
-
const {website, router} = this;
|
|
599
|
-
|
|
600
|
-
//console.log('HTTP_Website_Publisher handle_http');
|
|
601
|
-
//console.log('Object.keys(req)', Object.keys(req));
|
|
602
|
-
//console.log('Object.keys(req.headers)', Object.keys(req.headers));
|
|
603
|
-
|
|
604
|
-
const {url, method, statusCode, httpVersion} = req;
|
|
605
|
-
const accept_encoding = req.headers['accept-encoding'];
|
|
606
|
-
const {host} = req.headers;
|
|
607
|
-
|
|
608
|
-
// count of routes in the router?
|
|
609
|
-
// router.routes.length?
|
|
610
|
-
// router.num_routes?
|
|
611
|
-
|
|
612
|
-
//console.log('[httpVersion, host, url, statusCode, method, accept_endoding]', [httpVersion, host, url, statusCode, method, accept_encoding]);
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
//console.log('router', router);
|
|
616
|
-
//console.log('this.router', this.router);
|
|
617
|
-
//console.log('this', this);
|
|
618
|
-
//console.trace();
|
|
619
|
-
router.process(req, res);
|
|
620
|
-
|
|
621
|
-
*/
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
// can then get the port from after the : in the host.
|
|
626
|
-
//router.set_route(url,)
|
|
627
|
-
|
|
628
|
-
// But then the website itself, does it have a router?
|
|
629
|
-
// It (probably) should.
|
|
630
|
-
|
|
631
|
-
// Possibly the publisher has the router for the website.
|
|
632
|
-
|
|
633
|
-
// May have bundle already prepared anyway.
|
|
634
|
-
// Possibly the Website or the Website_Resource could do the bundling / building.
|
|
635
|
-
// Could even bundle into a ZIP file :)
|
|
636
|
-
|
|
637
|
-
//throw 'NYI';
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
|
|
1
|
+
// A publisher handles HTTP requests.
|
|
2
|
+
|
|
3
|
+
// This is going to take over some of the responsibilities of the old website resource, which was unfocused code that was
|
|
4
|
+
// doing some of the main / most important parts of serving the website.
|
|
5
|
+
|
|
6
|
+
const {each, Router, tof} = require('jsgui3-html');
|
|
7
|
+
const HTTP_Publisher = require('./http-publisher');
|
|
8
|
+
const {obs} = require('fnl');
|
|
9
|
+
|
|
10
|
+
// The Webpage bundler should be able to come up with the compiled JS and CSS, maybe even a favicon.
|
|
11
|
+
|
|
12
|
+
// HTTP_Webpageorsite_Publisher
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
const Website = require('jsgui3-website');
|
|
17
|
+
|
|
18
|
+
const Webpage_Bundler = require('../resources/processors/bundlers/webpage-bundler');
|
|
19
|
+
const Bundle = require('../resources/processors/bundlers/bundle');
|
|
20
|
+
|
|
21
|
+
// Now it's the very basics of a website publisher. Quite flexible but could do with more.
|
|
22
|
+
// Better integration with bundler
|
|
23
|
+
// Rendering webpages that are dynamic and therefore not bundled (eg user specific content).
|
|
24
|
+
// Though the js could be bundled. Maybe some of the controls could be bundled? Or semi-bundled?
|
|
25
|
+
|
|
26
|
+
// HTTP_Webpage_Publisher could be interesting.
|
|
27
|
+
// The Website Publisher could make use of some of its functionality.
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
// Handling HTTP / bundling for a specific page could be cool.
|
|
31
|
+
|
|
32
|
+
// A Webpage Publisher may be simpler and better to work on in the short term.
|
|
33
|
+
// Maybe would not need to be (as) concerned with routing.
|
|
34
|
+
// Could be useful for publishing a SPA of course, kind of a website but as a single page.
|
|
35
|
+
|
|
36
|
+
// This seems more like the server router these days
|
|
37
|
+
// The main server router seems to pass everything to this - maybe that will change.
|
|
38
|
+
|
|
39
|
+
// Maybe give it some kind of Website_Server????
|
|
40
|
+
|
|
41
|
+
// Have the Website_Server use the Website_Publisher????
|
|
42
|
+
|
|
43
|
+
// Need to somewhat separate concerns.
|
|
44
|
+
|
|
45
|
+
// Publisher here could be simple in terms of bundling, and then giving the paths to the router.
|
|
46
|
+
// And could have really simple code implementation of doing just that.
|
|
47
|
+
|
|
48
|
+
// This basically can be simple....
|
|
49
|
+
// But make the classes' structures more complicated where necessary to accommodate.
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
// Could be just a few lines of logic probably, at least the simplest core implementation.
|
|
53
|
+
|
|
54
|
+
// Think the server or the website already has a router, so have the website resource's router do the routing.
|
|
55
|
+
// Maybe upgrade the routers to handle premade (compressed) responses.
|
|
56
|
+
|
|
57
|
+
// Maybe better to bundle and publish resources.
|
|
58
|
+
// resource-processors in its own dir?
|
|
59
|
+
// as in it's not actually part of resources?
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
// Need to basically make this do very little.
|
|
65
|
+
|
|
66
|
+
// Publish (website, server_router)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
// Or publish it only under some URLs / domains....?
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
// Probably is worth by default having it use the HTTP_Website_Publisher with really simple server setups.
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
// Extend HTTP_Web_Item_Publisher HTTP_Web_Page_Or_Site_Publisher (synonym) ????
|
|
80
|
+
|
|
81
|
+
// Share functionality between webpage and website where useful.
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
const HTTP_Webpageorsite_Publisher = require('./http-webpageorsite-publisher');
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
class HTTP_Website_Publisher extends HTTP_Webpageorsite_Publisher {
|
|
89
|
+
// Website generally serves JS from a single address.
|
|
90
|
+
// Webpage could have its specific JS.
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
// Maybe the Publisher should not have its own router?
|
|
94
|
+
// But it provides items with paths from bundles it gets made to the website server's router.
|
|
95
|
+
|
|
96
|
+
// Def looks like its worth rearchitecturing this to provide more consistency on the lower level, and a 'just works' simplicity
|
|
97
|
+
// on the higher level.
|
|
98
|
+
|
|
99
|
+
// Plus some base classes that themselves don't do all that much, and then subclasses of them that do things in specific
|
|
100
|
+
// ways, so that implementations of specific parts are interchangable.
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
constructor(spec = {}) {
|
|
107
|
+
super(spec)
|
|
108
|
+
// A website property.
|
|
109
|
+
|
|
110
|
+
//console.trace();
|
|
111
|
+
//throw 'stop';
|
|
112
|
+
|
|
113
|
+
// spec webpage????
|
|
114
|
+
|
|
115
|
+
let website;
|
|
116
|
+
if (spec.website) {
|
|
117
|
+
if (spec.website instanceof Website) {
|
|
118
|
+
website = spec.website;
|
|
119
|
+
} else {
|
|
120
|
+
console.trace();
|
|
121
|
+
throw 'Expected spec.website to be of type "jsgui3-website" class instance';
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
Object.defineProperty(this, 'website', {
|
|
125
|
+
get() {
|
|
126
|
+
return website;
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
// A get_ready function for every level of the class for web publishing may help.
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
// The publisher should not have a router (for the moment???)
|
|
138
|
+
// It should however determine routes, and provide them to the router.
|
|
139
|
+
|
|
140
|
+
// Creating a Published_Website object perhaps.
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
/*
|
|
144
|
+
|
|
145
|
+
let router = new Router();
|
|
146
|
+
Object.defineProperty(this, 'router', {
|
|
147
|
+
get() {
|
|
148
|
+
return router;
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
*/
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
// Disk path client js being a property of the website itself?
|
|
160
|
+
// Critical overall functionality, dont want to remove it from here for the moment. See if not critical here.
|
|
161
|
+
|
|
162
|
+
/*
|
|
163
|
+
|
|
164
|
+
let disk_path_client_js;
|
|
165
|
+
if (spec.disk_path_client_js) disk_path_client_js = spec.disk_path_client_js;
|
|
166
|
+
Object.defineProperty(this, 'disk_path_client_js', {
|
|
167
|
+
get() {
|
|
168
|
+
return disk_path_client_js;
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
*/
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
// And this could be an observable too.
|
|
177
|
+
// May get admin pages working on a slightly lower level.
|
|
178
|
+
// Makes sense as they are for administering other pages (mostly).
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
//console.log('http-website-publisher disk_path_client_js', disk_path_client_js);
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
//throw 'stop';
|
|
186
|
+
// This could be an observable that acts sequentially and async.
|
|
187
|
+
|
|
188
|
+
// See about moving specific complexity elsewhere....
|
|
189
|
+
// See if what the website publisher does can be summed up expressively in JS.
|
|
190
|
+
|
|
191
|
+
// Uses a builder / packager on the website.
|
|
192
|
+
// Keeps track of a little bit of data on what's been published (could have an observable status event)
|
|
193
|
+
// Tells the server to publish it (on specified URL / Route - specified where? Defaults? Interchangable systems of default URLS paths?)
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
// But make this async (obs as well?)
|
|
197
|
+
// Have a sequence of events that takes place.
|
|
198
|
+
// Use the correct specific classes to do the correct specific things.
|
|
199
|
+
// Then make sure the implementations are correct.
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
// Will probably insert new bundling code here - but refer to advanced classes that handle the details.
|
|
209
|
+
|
|
210
|
+
console.log('\n\nskipping __old__setup_website_publishing');
|
|
211
|
+
console.trace();
|
|
212
|
+
console.log('\n\n');
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
const __old__setup_website_publishing = (website) => {
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
// Split up the bundling and response serving responsibilities.
|
|
219
|
+
// Should put it through the router (more as normal) when published.
|
|
220
|
+
// Maybe I'll need another 100 classes for this to work, maybe not, but should make everything explicit, but also concise,
|
|
221
|
+
// and then work on abbreviations and (unambiguous) shorthands.
|
|
222
|
+
// Or even settings for what the (default) shorthands do.
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
// Bundle it - Get some package(bundle) of pages.
|
|
226
|
+
|
|
227
|
+
// Website_Bundle perhaps...?
|
|
228
|
+
// All the static assets put together.
|
|
229
|
+
// Pages that don't have dynamic content are pre-rendered and compressed.
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
// 1) Bundle
|
|
236
|
+
// 2) Publish that bundle
|
|
237
|
+
// 2a) Provide the router with all the necessary URLs and (compressed) pregenerated responses from that bundle.
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
// Website_Bundle_Publisher perhaps....?
|
|
241
|
+
|
|
242
|
+
// Def seems worth it to refactor it into still more complicated classes, but to aim for really simple and concise code within
|
|
243
|
+
// those classes, at least when it comes to a simple and intuitive API that represents what is going on.
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
//console.log('website', website);
|
|
262
|
+
//console.log('website.pages', website.pages);
|
|
263
|
+
//console.log('website.pages.length()', website.pages.length());
|
|
264
|
+
//throw 'stop';
|
|
265
|
+
|
|
266
|
+
// This is currently really inflexible for a website with multiple pages.
|
|
267
|
+
// Pages could be given names.
|
|
268
|
+
// Don't want to be too prescriptive here, but do want to get this bundling and working.
|
|
269
|
+
|
|
270
|
+
// Do want to get it right in theory and in structure for a variety of possibilities.
|
|
271
|
+
|
|
272
|
+
// Should pay more attention to setting up the headers on the responses.
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
// should the website have a 'main' or 'front' or 'first' page, with it having its HTML rendered?
|
|
281
|
+
return obs((next, complete, error) => {
|
|
282
|
+
(async () => {
|
|
283
|
+
// not iterating properly through the collection without ._arr.
|
|
284
|
+
// May make more sense to have 2 versions,
|
|
285
|
+
// for 1 page
|
|
286
|
+
// for 2+ pages
|
|
287
|
+
const opts_bundling = {};
|
|
288
|
+
if (disk_path_client_js) opts_bundling.disk_path_client_js = disk_path_client_js;
|
|
289
|
+
|
|
290
|
+
if (website.pages._arr.length === 0) {
|
|
291
|
+
throw 'NYI';
|
|
292
|
+
} else if (website.pages._arr.length === 1) {
|
|
293
|
+
const page = website.pages._arr[0];
|
|
294
|
+
const obs_bundling = Webpage_Bundler.bundle_web_page(page, opts_bundling);
|
|
295
|
+
//console.log('doing bundling');
|
|
296
|
+
//console.log('obs_bundling', obs_bundling);
|
|
297
|
+
//throw 'stop';
|
|
298
|
+
obs_bundling.on('complete', obs_bundling_res => {
|
|
299
|
+
// Should be a Bundle rather than a Buffer?
|
|
300
|
+
console.log('obs_bundling res', obs_bundling_res);
|
|
301
|
+
// Need to have the HTML rendering and HTTP serving here as well.
|
|
302
|
+
//const page_bundle = res;
|
|
303
|
+
if (obs_bundling_res instanceof Bundle) {
|
|
304
|
+
//console.log('1) obs_bundling_res._arr.length', obs_bundling_res._arr.length);
|
|
305
|
+
// then need to handle the page construction and routing of http requests.
|
|
306
|
+
console.log('obs_bundling_res._arr.length', obs_bundling_res._arr.length);
|
|
307
|
+
each(obs_bundling_res, item => {
|
|
308
|
+
//console.log('item', item);
|
|
309
|
+
//console.log('item.path', item.path, item['content-type']);
|
|
310
|
+
if (item['content-type']) {
|
|
311
|
+
const ct = item['content-type'];
|
|
312
|
+
if (ct === 'text/html') {
|
|
313
|
+
const http_serve_html = (req, res) => {
|
|
314
|
+
res.writeHead(200, {
|
|
315
|
+
'Content-Type': 'text/html'
|
|
316
|
+
});
|
|
317
|
+
res.end(item.value, 'utf-8');
|
|
318
|
+
}
|
|
319
|
+
router.set_route(item.path, (req, res) => {
|
|
320
|
+
http_serve_html(req, res);
|
|
321
|
+
});
|
|
322
|
+
} else {
|
|
323
|
+
const http_serve_any = (req, res) => {
|
|
324
|
+
res.writeHead(200, {
|
|
325
|
+
'Content-Type': ct
|
|
326
|
+
});
|
|
327
|
+
res.end(item.value, 'utf-8');
|
|
328
|
+
}
|
|
329
|
+
router.set_route(item.path, (req, res) => {
|
|
330
|
+
http_serve_any(req, res);
|
|
331
|
+
});
|
|
332
|
+
//throw 'NYI';
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
} else {
|
|
336
|
+
throw 'NYI';
|
|
337
|
+
}
|
|
338
|
+
})
|
|
339
|
+
|
|
340
|
+
//console.trace();
|
|
341
|
+
//throw 'stop';
|
|
342
|
+
complete(obs_bundling_res);
|
|
343
|
+
} else {
|
|
344
|
+
|
|
345
|
+
console.log('tof(obs_bundling_res)', tof(obs_bundling_res));
|
|
346
|
+
|
|
347
|
+
console.trace();
|
|
348
|
+
throw 'stop';
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
} else if (website.pages._arr.length > 1) {
|
|
352
|
+
throw 'NYI';
|
|
353
|
+
for (const page in website.pages._arr) {
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
// With multiple pages, add page to bundle.
|
|
358
|
+
|
|
359
|
+
const obs_bundling = Webpage_Bundler.bundle_web_page(page, opts_bundling);
|
|
360
|
+
//console.log('doing bundling');
|
|
361
|
+
//console.log('obs_bundling', obs_bundling);
|
|
362
|
+
|
|
363
|
+
//throw 'stop';
|
|
364
|
+
|
|
365
|
+
obs_bundling.on('complete', res => {
|
|
366
|
+
//console.log('obs_bundling res', res);
|
|
367
|
+
const page_bundle = res;
|
|
368
|
+
|
|
369
|
+
console.log('page_bundle._arr.length', page_bundle._arr.length);
|
|
370
|
+
|
|
371
|
+
//complete(bundle);
|
|
372
|
+
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
const old = () => {
|
|
377
|
+
obs_bundling.on('complete', res => {
|
|
378
|
+
//console.log('obs_bundling res', res);
|
|
379
|
+
const bundle = res;
|
|
380
|
+
//console.log('bundle._arr.length', bundle._arr.length);
|
|
381
|
+
//console.log('Object.keys(bundle)', Object.keys(bundle));
|
|
382
|
+
|
|
383
|
+
if (bundle._arr.length === 1) {
|
|
384
|
+
// And check it's HTML inside...?
|
|
385
|
+
|
|
386
|
+
const bundled_item = bundle._arr[0];
|
|
387
|
+
//console.log('bundled_item', bundled_item);
|
|
388
|
+
|
|
389
|
+
if (bundled_item['content-type']) {
|
|
390
|
+
const ct = bundled_item['content-type'];
|
|
391
|
+
if (ct === 'text/html') {
|
|
392
|
+
const http_serve_html = (req, res) => {
|
|
393
|
+
res.writeHead(200, {
|
|
394
|
+
'Content-Type': 'text/html'
|
|
395
|
+
});
|
|
396
|
+
res.end(bundled_item.value, 'utf-8');
|
|
397
|
+
}
|
|
398
|
+
router.set_route(bundled_item.path, (req, res) => {
|
|
399
|
+
http_serve_html(req, res);
|
|
400
|
+
});
|
|
401
|
+
} else {
|
|
402
|
+
throw 'NYI';
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
} else {
|
|
406
|
+
throw 'NYI';
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// need to create / use the handler for it here.
|
|
410
|
+
// will have various http handler functions to reference and use.
|
|
411
|
+
// will have details of http handling in other files.
|
|
412
|
+
|
|
413
|
+
// Maybe use an HTML publisher for this? (if it's HTML).
|
|
414
|
+
// Or publisher by mime type (lookup).
|
|
415
|
+
|
|
416
|
+
// create http handler function....
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
} else {
|
|
421
|
+
|
|
422
|
+
// Multiple items at multiple paths....
|
|
423
|
+
|
|
424
|
+
each(bundle, item => {
|
|
425
|
+
//console.log('item', item);
|
|
426
|
+
//console.log('item.path', item.path, item['content-type']);
|
|
427
|
+
|
|
428
|
+
if (item['content-type']) {
|
|
429
|
+
const ct = item['content-type'];
|
|
430
|
+
if (ct === 'text/html') {
|
|
431
|
+
const http_serve_html = (req, res) => {
|
|
432
|
+
res.writeHead(200, {
|
|
433
|
+
'Content-Type': 'text/html'
|
|
434
|
+
});
|
|
435
|
+
res.end(item.value, 'utf-8');
|
|
436
|
+
}
|
|
437
|
+
router.set_route(item.path, (req, res) => {
|
|
438
|
+
http_serve_html(req, res);
|
|
439
|
+
});
|
|
440
|
+
} else {
|
|
441
|
+
const http_serve_any = (req, res) => {
|
|
442
|
+
res.writeHead(200, {
|
|
443
|
+
'Content-Type': ct
|
|
444
|
+
});
|
|
445
|
+
res.end(item.value, 'utf-8');
|
|
446
|
+
}
|
|
447
|
+
router.set_route(item.path, (req, res) => {
|
|
448
|
+
http_serve_any(req, res);
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
//throw 'NYI';
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
} else {
|
|
455
|
+
throw 'NYI';
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
})
|
|
459
|
+
|
|
460
|
+
//console.trace();
|
|
461
|
+
//throw 'NYI';
|
|
462
|
+
}
|
|
463
|
+
})
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+
//console.log(`${property}: ${object[property]}`);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
})().catch(err => {
|
|
475
|
+
console.error(err);
|
|
476
|
+
});
|
|
477
|
+
});
|
|
478
|
+
// put pages into a router here...
|
|
479
|
+
// however, may need to be on the lookout for other content that needs to be bundled with each page in the site.
|
|
480
|
+
|
|
481
|
+
// Now let's try bundling an active JS client.
|
|
482
|
+
// May need to compile / render JSGUI Controls to HTML / full HTML pages.
|
|
483
|
+
|
|
484
|
+
// And unspecified pages such as admin pages?
|
|
485
|
+
|
|
486
|
+
|
|
487
|
+
//throw 'NYI';
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
|
|
491
|
+
if (website) {
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
console.trace();
|
|
495
|
+
|
|
496
|
+
throw 'NYI - HTTP_Website_Publisher needs to publish specified website';
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
// Website_Bundle class would help.
|
|
500
|
+
|
|
501
|
+
// jsgui3-website-bundle.
|
|
502
|
+
// Could make a separate module for it, give it a very simple API.
|
|
503
|
+
// Probably would only want to bundle websites on the server though.
|
|
504
|
+
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
|
|
510
|
+
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
// Prepare website for publishing
|
|
514
|
+
// Prepare being building static resources, making a list of the static routes / page content to serve.
|
|
515
|
+
// Static_Route_Content clases somewhere too.
|
|
516
|
+
|
|
517
|
+
|
|
518
|
+
// Use many different class names to help keep track of what the objects do, and allow for flexibility.
|
|
519
|
+
|
|
520
|
+
|
|
521
|
+
|
|
522
|
+
// Then the type of the website....
|
|
523
|
+
// Do make use of runtime polymorphism and type checking.
|
|
524
|
+
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
|
|
533
|
+
/*
|
|
534
|
+
|
|
535
|
+
const obs_setup = setup_website_publishing(website);
|
|
536
|
+
|
|
537
|
+
|
|
538
|
+
obs_setup.on('complete', res_complete => {
|
|
539
|
+
console.log('setup complete');
|
|
540
|
+
this.raise('ready');
|
|
541
|
+
|
|
542
|
+
|
|
543
|
+
})
|
|
544
|
+
|
|
545
|
+
*/
|
|
546
|
+
} else {
|
|
547
|
+
|
|
548
|
+
// Do the async get_ready function....
|
|
549
|
+
|
|
550
|
+
(async() => {
|
|
551
|
+
|
|
552
|
+
await this.get_ready();
|
|
553
|
+
this.raise('ready');
|
|
554
|
+
|
|
555
|
+
})();
|
|
556
|
+
|
|
557
|
+
|
|
558
|
+
//
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
// Create a router for the website if it does not already have one.
|
|
562
|
+
// Or maybe not....
|
|
563
|
+
|
|
564
|
+
// Do we already know all of the pages in the website?
|
|
565
|
+
// Maybe there are dynamic pages.
|
|
566
|
+
|
|
567
|
+
// Probably best to come up with a bundle here, or at an early stage.
|
|
568
|
+
|
|
569
|
+
// .prepare_bundle?
|
|
570
|
+
|
|
571
|
+
// .bundle?
|
|
572
|
+
// seems clearest that we will be getting / preparing multiple files.
|
|
573
|
+
|
|
574
|
+
// Bundling and compiling web content seems like a better thing to get working before serving (or attempting to serve) it.
|
|
575
|
+
// .build?
|
|
576
|
+
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
async get_ready() {
|
|
580
|
+
await super.get_ready();
|
|
581
|
+
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
|
|
585
|
+
handle_http(req, res) {
|
|
586
|
+
// Because it's already been set up in the router! It should have been.
|
|
587
|
+
return this.router.process(req, res);
|
|
588
|
+
|
|
589
|
+
// Called from a different context? Doubt we want that.
|
|
590
|
+
// Now called strangely, without context.
|
|
591
|
+
|
|
592
|
+
|
|
593
|
+
// The router does it all...???
|
|
594
|
+
|
|
595
|
+
|
|
596
|
+
/*
|
|
597
|
+
|
|
598
|
+
const {website, router} = this;
|
|
599
|
+
|
|
600
|
+
//console.log('HTTP_Website_Publisher handle_http');
|
|
601
|
+
//console.log('Object.keys(req)', Object.keys(req));
|
|
602
|
+
//console.log('Object.keys(req.headers)', Object.keys(req.headers));
|
|
603
|
+
|
|
604
|
+
const {url, method, statusCode, httpVersion} = req;
|
|
605
|
+
const accept_encoding = req.headers['accept-encoding'];
|
|
606
|
+
const {host} = req.headers;
|
|
607
|
+
|
|
608
|
+
// count of routes in the router?
|
|
609
|
+
// router.routes.length?
|
|
610
|
+
// router.num_routes?
|
|
611
|
+
|
|
612
|
+
//console.log('[httpVersion, host, url, statusCode, method, accept_endoding]', [httpVersion, host, url, statusCode, method, accept_encoding]);
|
|
613
|
+
|
|
614
|
+
|
|
615
|
+
//console.log('router', router);
|
|
616
|
+
//console.log('this.router', this.router);
|
|
617
|
+
//console.log('this', this);
|
|
618
|
+
//console.trace();
|
|
619
|
+
router.process(req, res);
|
|
620
|
+
|
|
621
|
+
*/
|
|
622
|
+
|
|
623
|
+
|
|
624
|
+
|
|
625
|
+
// can then get the port from after the : in the host.
|
|
626
|
+
//router.set_route(url,)
|
|
627
|
+
|
|
628
|
+
// But then the website itself, does it have a router?
|
|
629
|
+
// It (probably) should.
|
|
630
|
+
|
|
631
|
+
// Possibly the publisher has the router for the website.
|
|
632
|
+
|
|
633
|
+
// May have bundle already prepared anyway.
|
|
634
|
+
// Possibly the Website or the Website_Resource could do the bundling / building.
|
|
635
|
+
// Could even bundle into a ZIP file :)
|
|
636
|
+
|
|
637
|
+
//throw 'NYI';
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
|
|
641
641
|
module.exports = HTTP_Website_Publisher;
|