jsgui3-server 0.0.75 → 0.0.77
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/client-side-popup-menu-button.html +93 -93
- package/examples/controls/_html-server-color-palette.js +114 -114
- package/examples/controls/html-server-combo-box.js +104 -104
- package/examples/controls/html-server-list.js +98 -98
- package/examples/controls/html-server-popup-menu-button.js +114 -114
- package/examples/controls/html-server-start-stop-toggle-button.js +146 -146
- package/examples/controls/scs-arrow-button.js +36 -36
- package/examples/controls/scs-date-picker.js +157 -157
- package/examples/controls/scs-file-browser.js +82 -82
- package/examples/controls/scs-item.js +159 -159
- package/examples/controls/scs-month-arrow-selector.js +126 -126
- package/examples/controls/scs-month-view.js +95 -95
- package/examples/controls/scs-start-stop-toggle-button.js +40 -40
- package/examples/controls/scs-tree.js +49 -49
- package/examples/controls/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/demos/square_box.js +324 -324
- package/examples/html-rendering.js +20 -20
- package/examples/html-server.js +100 -100
- package/fs2.js +1836 -1836
- package/module.js +21 -21
- package/old/single-control-server.js +418 -418
- package/package.json +44 -42
- package/publishing/function-publisher.js +202 -202
- package/publishing/notes.md +5 -5
- package/publishing/observable-publisher.js +118 -118
- package/publishing/resource-publisher.js +306 -306
- package/resources/data-resource.js +104 -104
- package/resources/fs-resource.js +148 -148
- package/resources/jsbuilder/Abstract_Single_Declaration.js +105 -0
- package/resources/jsbuilder/Abstract_Single_Declaration_Sequence.js +43 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Abstract_Node.js +62 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Abstract_Node_Group.js +42 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Group_Shared.js +62 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node.js +94 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_0-Core.js +228 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_1-Babel.js +338 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_10-Changing.js +40 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_2.1.1-Child.js +97 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_2.1.2-Parent.js +38 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_2.1.3-Ancestor.js +62 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_2.2-Inner.js +44 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_2.3-All.js +73 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_2.4-Sibling.js +93 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_2.5-Available_In_Scope.js +29 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_2.9-Signature.js +116 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3-Basics.js +160 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.0.0-Basics_First.js +179 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.0.1-Basics_Second.js +88 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.0.99-Basics_Last.js +92 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.1-Basics_Each.js +137 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.1.5-Basics_Count.js +74 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.2-Basics_Filter.js +40 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.3-Basics_Collect.js +86 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.4-Basics_Select.js +43 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.5-Basics_Find.js +41 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_3.6-Basics_Callmap.js +55 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_4.0-Index_Indexes.js +46 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_4.1-Index.js +344 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_5.0-Category.js +39 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_5.1-Category_Identifier.js +31 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_5.2-Category_Literal.js +29 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_5.3-Category_Expression.js +27 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_5.4-Category_Pattern.js +9 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_5.5-Category_Declaration.js +44 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_5.6-Category_Statement.js +22 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_6.0-Type.js +87 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_6.1-Type_Class_Declaration.js +9 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_6.2-Type_Variable_Declaration.js +28 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_6.3-Type_Variable_Declarator.js +29 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_7-Query.js +737 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_8-Features.js +65 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_9-Planning.js +32 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Arrangement.js +15 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Node_Declared_Object.js +306 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Node_Feature.js +78 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Node_Feature_Declaration.js +249 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Node_Feature_Declarator.js +139 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/JS_AST_Root_Node_Feature.js +10 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/JS_AST_Root_Node_Feature_Exported.js +101 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/JS_AST_Root_Node_Feature_Exports.js +61 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/JS_AST_Root_Node_Interpreted.js +180 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/_JSGUI_Root_Node_Interpreted.js +43 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Feature/JS_AST_Root_Node_Feature/special_case_objectassign_to_object.js +12 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Node_Group.js +35 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Operation.js +11 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Operation_On_Relationship.js +32 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Ordered_Relationship_Node_To_Group.js +38 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Ordinal.js +40 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Ordinal_Relationship.js +25 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Relationship_Node_To_Group.js +201 -0
- package/resources/jsbuilder/JS_AST/JS_AST_Relationship_Node_Within_Group_To_Node.js +44 -0
- package/resources/jsbuilder/JS_AST/_JS_AST_Node_3.8-Query_Features.js +77 -0
- package/resources/jsbuilder/JS_AST/query/all.js +0 -0
- package/resources/jsbuilder/JS_AST/query/enable_array_as_queryable.js +228 -0
- package/resources/jsbuilder/JS_AST/query/find_object_keys.js +405 -0
- package/resources/jsbuilder/JS_AST/query/node_queries.js +9 -0
- package/resources/jsbuilder/JS_AST/query/root_queries.js +0 -0
- package/resources/jsbuilder/JS_AST/query/root_query_identidy.js +12 -0
- package/resources/jsbuilder/JS_AST_Node_Extended/JSGUI_Singular_Declaration.js +86 -0
- package/resources/jsbuilder/JS_AST_Node_Extended/JS_AST_Node_Declaration.js +124 -0
- package/resources/jsbuilder/JS_AST_Node_Extended/JS_AST_Node_Extended.js +88 -0
- package/resources/jsbuilder/JS_AST_Node_Extended/JS_AST_Node_Extended_0-Core.js +11 -0
- package/resources/jsbuilder/JS_Builder.js +10 -36
- package/resources/jsbuilder/JS_File/Feature/JS_File_Declared_Object.js +32 -0
- package/resources/jsbuilder/JS_File/Feature/JS_File_Exported_Object_Info.js +26 -0
- package/resources/jsbuilder/JS_File/Feature/JS_File_Exports.js +79 -0
- package/resources/jsbuilder/JS_File/Feature/JS_File_Feature.js +18 -0
- package/resources/jsbuilder/JS_File/Feature/JS_File_Imported_Object_Info.js +26 -0
- package/resources/jsbuilder/JS_File/Feature/JS_File_Imports.js +9 -0
- package/resources/jsbuilder/JS_File/JS_File.js +12 -0
- package/resources/jsbuilder/JS_File/JS_File_0-Core.js +202 -0
- package/resources/jsbuilder/JS_File/JS_File_1-Early_Parse.js +175 -0
- package/resources/jsbuilder/JS_File/JS_File_2-Babel.js +81 -0
- package/resources/jsbuilder/JS_File/JS_File_3-JS_AST_Node.js +86 -0
- package/resources/jsbuilder/JS_File/JS_File_4-Query.js +414 -0
- package/resources/jsbuilder/JS_File/JS_File_4.1-Query_Features.js +415 -0
- package/resources/jsbuilder/JS_File/JS_File_5-Planning.js +59 -0
- package/resources/jsbuilder/JS_File/JS_File_6-Changing.js +24 -0
- package/resources/jsbuilder/JS_File/JS_File_Export_Reference.js +12 -0
- package/resources/jsbuilder/JS_File/JS_File_Import_Reference.js +24 -0
- package/resources/jsbuilder/JS_File/JS_File_Import_References.js +32 -0
- package/resources/jsbuilder/JS_File/JS_File_Processor.js +16 -0
- package/resources/jsbuilder/JS_File/JS_Files.js +16 -0
- package/resources/jsbuilder/Module.js +14 -0
- package/resources/jsbuilder/Platform.js +13 -53
- package/resources/jsbuilder/Platforms.js +69 -15
- package/resources/jsbuilder/Project.js +109 -0
- package/resources/jsbuilder/Reference.js +1 -1
- package/resources/jsbuilder/Reference_Sequence.js +16 -7
- package/resources/jsbuilder/Scope.js +30 -0
- package/resources/jsbuilder/Variable_Name_Provider.js +43 -0
- package/resources/jsbuilder/_JS_File.js +226 -0
- package/resources/jsbuilder/ast_query.js +21 -0
- package/resources/jsbuilder/babel/babel_consts.js +150 -0
- package/resources/jsbuilder/babel/babel_node_tools.js +542 -0
- package/resources/jsbuilder/babel/deep_iterate/deep_iterate_babel.js +604 -0
- package/resources/jsbuilder/build.js +16 -0
- package/resources/jsbuilder/platform_notes.md +66 -0
- package/resources/jsbuilder/test/test_ast_node.js +451 -0
- package/resources/jsbuilder/test/test_js_file.js +303 -11
- package/resources/jsbuilder/test/test_project.js +157 -0
- package/resources/local-server-info-resource.js +78 -78
- package/resources/process-js.js +537 -537
- package/resources/server-resource-pool.js +84 -84
- package/resources/website-css-resource.js +411 -411
- package/resources/website-javascript-resource.js +761 -751
- package/resources/website-resource.js +390 -390
- package/resources/website-static-html-resource.js +196 -196
- package/server.js +170 -170
- package/single-control-server.js +398 -398
- package/single-page-app.js +129 -129
- package/resources/jsbuilder/Declaration.js +0 -15
- package/resources/jsbuilder/Declaration_Sequence.js +0 -15
- package/resources/jsbuilder/JS_File.js +0 -77
|
@@ -1,390 +1,390 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by James on 29/07/2014.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
// Want to get the core resources working and tested.
|
|
6
|
-
// Want to run a clock website / service to start with.
|
|
7
|
-
// The server could have a clock, while clients could connect to it and share the information.
|
|
8
|
-
// Could also experiment with P2P distribution of the data.
|
|
9
|
-
// A clock is also useful because it contains time signals so we can see how long it takes for data to reach various machines.
|
|
10
|
-
|
|
11
|
-
// A web resource in particular?
|
|
12
|
-
// Any need for an HTML resource?
|
|
13
|
-
// Probably not - have web resource handle HTML and websockets.
|
|
14
|
-
|
|
15
|
-
// Resources could also have events which objects can listen to.
|
|
16
|
-
// Programmatic objects can listen.
|
|
17
|
-
// The resources may broadcast to whatever is listening.
|
|
18
|
-
|
|
19
|
-
// Also, maintaining one connection stream, communicating with multiple resources - could connect through a Resource Pool, or maybe there
|
|
20
|
-
// could be a Multi Resource Publisher that publishes a bunch of resources.
|
|
21
|
-
|
|
22
|
-
// The Application router at the moment sending requests to resources.
|
|
23
|
-
// I am thinking that rather than doing that, the requests should be handled by a resource publisher that interacts with the resource and publishes it over HTTP.
|
|
24
|
-
|
|
25
|
-
// Resources in general won't handle HTTP requests, though they will have the capability.
|
|
26
|
-
// More likely that a resource, when it is served online, will be served using a Resource Publisher (which is itself a resource), which handles HTTP implementation details that would otherwise have
|
|
27
|
-
// to be repeated between resources.
|
|
28
|
-
|
|
29
|
-
//define(["./jsgui-lang-util", './abstract-resource'], function(jsgui, AR) {
|
|
30
|
-
|
|
31
|
-
// Do this not with AMD?
|
|
32
|
-
|
|
33
|
-
// May need Website_Data_Resource
|
|
34
|
-
// Would be configured within the node app, client has maximum autoconfig from connecting to the server, and integration with client-side controls.
|
|
35
|
-
// With the DB admin, it's about returining queries (maybe from RAM) about table data.
|
|
36
|
-
// /data/then the api?
|
|
37
|
-
|
|
38
|
-
// Respond to both data HTTP requests and websocket connections.
|
|
39
|
-
|
|
40
|
-
// HTTP data request -> response seems like the most important step now.
|
|
41
|
-
|
|
42
|
-
// An fs Resource would be of use for file system browser.
|
|
43
|
-
// Could have a client-side fs resource that connects to a veriety of services, could have one that connects to the server-side fs resource.
|
|
44
|
-
|
|
45
|
-
// Need to connect a data-providing resource to the UI component in cases where it's not secure to do so automatically.
|
|
46
|
-
// It would be much more secure to bring up an NTP provision service automatically than a file system one. Don't want to take that risk now.
|
|
47
|
-
//
|
|
48
|
-
|
|
49
|
-
var Site_Images = require("./website-image-resource");
|
|
50
|
-
|
|
51
|
-
//console.log('1) Site_Images', Site_Images);
|
|
52
|
-
|
|
53
|
-
var jsgui = require("jsgui3-html");
|
|
54
|
-
const { each, get_a_sig, is_defined, tof } = jsgui;
|
|
55
|
-
|
|
56
|
-
//var Web_Resource = require('./website-resource');
|
|
57
|
-
const Resource = jsgui.Resource;
|
|
58
|
-
const Router = jsgui.Router;
|
|
59
|
-
//const Evented_Class = jsgui.Evented_Class;
|
|
60
|
-
|
|
61
|
-
var Resource_Pool = require("./server-resource-pool");
|
|
62
|
-
//var Resource_Web_Admin = require('../web-admin');
|
|
63
|
-
|
|
64
|
-
var Site_JavaScript = require("./website-javascript-resource");
|
|
65
|
-
//console.log('1) Site_JavaScript', Site_JavaScript);
|
|
66
|
-
var Site_CSS = require("./website-css-resource");
|
|
67
|
-
var Site_Static_HTML = require("./website-static-html-resource");
|
|
68
|
-
//var DB_Web_Resource = require('../../web/db-resource-postgres');
|
|
69
|
-
//var database_resource_factory = require('../../db/resource/factory');
|
|
70
|
-
|
|
71
|
-
const Resource_Publisher = require("../publishing/resource-publisher");
|
|
72
|
-
const Observable_Publisher = require("../publishing/observable-publisher");
|
|
73
|
-
const Function_Publisher = require("../publishing/function-publisher");
|
|
74
|
-
//const Data_Resource = require("./data-resource");
|
|
75
|
-
|
|
76
|
-
class Website_Resource extends Resource {
|
|
77
|
-
constructor(spec = {}) {
|
|
78
|
-
super(spec);
|
|
79
|
-
// A bit of a special resource here because it has its own resource_pool.
|
|
80
|
-
var resource_pool = new Resource_Pool({
|
|
81
|
-
name: "Website Resource Pool"
|
|
82
|
-
});
|
|
83
|
-
this.resource_pool = resource_pool;
|
|
84
|
-
var database_spec = spec.database;
|
|
85
|
-
var web_database_resource;
|
|
86
|
-
|
|
87
|
-
if (database_spec) {
|
|
88
|
-
database_spec.name = database_spec.name || database_spec.database_name;
|
|
89
|
-
var database_resource = database_resource_factory(database_spec);
|
|
90
|
-
database_resource.start();
|
|
91
|
-
// should start automatically when in the pool?
|
|
92
|
-
// does the pool need to be told to start?
|
|
93
|
-
// Though probably don't want to start the resource on initialization.
|
|
94
|
-
resource_pool.add(database_resource);
|
|
95
|
-
web_database_resource = new DB_Web_Resource({
|
|
96
|
-
database: database_resource,
|
|
97
|
-
meta: {
|
|
98
|
-
name: "Web DB",
|
|
99
|
-
pool: resource_pool
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (web_database_resource) {
|
|
105
|
-
resource_pool.add(web_database_resource);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
var router = new Router({
|
|
109
|
-
name: "Site Router"
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
this.router = router;
|
|
113
|
-
|
|
114
|
-
var spec_web_admin = {
|
|
115
|
-
//'web_database': web_database_resource,
|
|
116
|
-
meta: {
|
|
117
|
-
name: "Web Admin"
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
if (web_database_resource) {
|
|
122
|
-
spec_web_admin.web_database = web_database_resource;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
var img_resource = new Site_Images({
|
|
126
|
-
//'meta': {
|
|
127
|
-
name: "Site Images",
|
|
128
|
-
pool: resource_pool
|
|
129
|
-
// }
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
var js_resource = new Site_JavaScript({
|
|
133
|
-
//'meta': {
|
|
134
|
-
name: "Site JavaScript",
|
|
135
|
-
pool: resource_pool
|
|
136
|
-
//}
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
// Also want a static HTML server.
|
|
140
|
-
// Would serve index.html by default I think???
|
|
141
|
-
// Probably with the static or simplest settings.
|
|
142
|
-
|
|
143
|
-
var static_html_resource;
|
|
144
|
-
|
|
145
|
-
if (spec == "static") {
|
|
146
|
-
static_html_resource = new Site_Static_HTML({
|
|
147
|
-
//'meta': {
|
|
148
|
-
name: "Static HTML",
|
|
149
|
-
pool: resource_pool
|
|
150
|
-
//}
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
resource_pool.push(static_html_resource);
|
|
154
|
-
|
|
155
|
-
// Perhaps set it up with the specific files (automatically)?
|
|
156
|
-
// Probably with the index.html
|
|
157
|
-
}
|
|
158
|
-
var css_resource = new Site_CSS({
|
|
159
|
-
//'meta': {
|
|
160
|
-
name: "Site CSS",
|
|
161
|
-
pool: resource_pool
|
|
162
|
-
//}
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
js_resource.on('extracted-controls-css', str_extracted_css => {
|
|
167
|
-
css_resource.serve_str_css('controls.css', str_extracted_css);
|
|
168
|
-
// Will serve this as controls.css
|
|
169
|
-
// Separate HTTP request, will get more CSS for the moment.
|
|
170
|
-
|
|
171
|
-
});
|
|
172
|
-
// javascript and css resources.
|
|
173
|
-
resource_pool.push(router);
|
|
174
|
-
resource_pool.push(img_resource);
|
|
175
|
-
resource_pool.push(js_resource);
|
|
176
|
-
resource_pool.push(css_resource);
|
|
177
|
-
//resource_pool.push(data_resource);
|
|
178
|
-
|
|
179
|
-
// anything ending in .css as well.
|
|
180
|
-
// Routing maybe wouldn't work like that.
|
|
181
|
-
//router.set_route('*.css', css_resource, css_resource.process);
|
|
182
|
-
|
|
183
|
-
router.set_route("css/*", css_resource, css_resource.process);
|
|
184
|
-
router.set_route("js/*", js_resource, js_resource.process);
|
|
185
|
-
// As well as this, it could get the JavaScript resource to serve the JavaScript from the app's js directory.
|
|
186
|
-
js_resource.serve_directory("js");
|
|
187
|
-
router.set_route("img/*", img_resource, img_resource.process);
|
|
188
|
-
router.set_route("images/*", img_resource, img_resource.process);
|
|
189
|
-
this.map_resource_publishers = this.map_resource_publishers || {};
|
|
190
|
-
router.set_route("resources/:resource_name/*", this, (req, res) => {
|
|
191
|
-
let { url, method } = req;
|
|
192
|
-
let s_url = url.split("/");
|
|
193
|
-
let resource_short_name = s_url[2];
|
|
194
|
-
let resource_publisher = this.map_resource_publishers[resource_short_name];
|
|
195
|
-
if (resource_publisher) {
|
|
196
|
-
resource_publisher.handle_http(req, res);
|
|
197
|
-
}
|
|
198
|
-
});
|
|
199
|
-
if (!is_defined(spec)) spec = {};
|
|
200
|
-
this.resource_pool = resource_pool;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
publishing_get_pub(item) {
|
|
204
|
-
let pub;
|
|
205
|
-
if (item instanceof jsgui.Resource) {
|
|
206
|
-
pub = new Resource_Publisher({
|
|
207
|
-
resource: item
|
|
208
|
-
});
|
|
209
|
-
} else {
|
|
210
|
-
// if its a function
|
|
211
|
-
// return that function call to the response.
|
|
212
|
-
let t_item = typeof item;
|
|
213
|
-
if (t_item === "function") {
|
|
214
|
-
// Function_Call_Publisher
|
|
215
|
-
// could respec this.
|
|
216
|
-
// And the Function_Publisher operates through the Publisher API. Not sure what that is right now though.
|
|
217
|
-
|
|
218
|
-
pub = new Function_Publisher({
|
|
219
|
-
fn: item
|
|
220
|
-
});
|
|
221
|
-
//this.map_resource_publishers[published_name] = pub;
|
|
222
|
-
//
|
|
223
|
-
} else {
|
|
224
|
-
if (item.next && item.complete && item.error) {
|
|
225
|
-
// assuming observable
|
|
226
|
-
// Observable publisher
|
|
227
|
-
// One way sending...
|
|
228
|
-
//console.log('using Observable_Publisher');
|
|
229
|
-
pub = new Observable_Publisher({
|
|
230
|
-
obs: item
|
|
231
|
-
});
|
|
232
|
-
// or not a resource publisher, an observable publisher.
|
|
233
|
-
//this.map_resource_publishers = this.map_resource_publishers || {};
|
|
234
|
-
//this.map_resource_publishers[published_name] = obs_pub;
|
|
235
|
-
|
|
236
|
-
//console.log('2) this', this);
|
|
237
|
-
//console.log('this.map_resource_publishers', this.map_resource_publishers);
|
|
238
|
-
//console.trace();
|
|
239
|
-
} else {
|
|
240
|
-
console.log("item", item);
|
|
241
|
-
throw "Unrecognised item type. Possibly node module versions are wrong / have not been linked fully.";
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
//if (item instanceof Evented_Class) {
|
|
245
|
-
}
|
|
246
|
-
return pub;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
// publish within resources?
|
|
250
|
-
publish(published_name, item, schema) {
|
|
251
|
-
let sig = get_a_sig(arguments),
|
|
252
|
-
a = arguments,
|
|
253
|
-
l = a.length;
|
|
254
|
-
const single = (published_name, item) => {
|
|
255
|
-
if (item instanceof jsgui.Resource) {
|
|
256
|
-
let resource_publisher = new Resource_Publisher({
|
|
257
|
-
resource: item,
|
|
258
|
-
name: published_name
|
|
259
|
-
});
|
|
260
|
-
this.map_resource_publishers[published_name] = resource_publisher;
|
|
261
|
-
|
|
262
|
-
item.name = item.name || published_name;
|
|
263
|
-
// add that resource!
|
|
264
|
-
// (to the pool?)
|
|
265
|
-
//console.log('item', item);
|
|
266
|
-
this.resource_pool.add(item);
|
|
267
|
-
|
|
268
|
-
//console.log('Object.keys(this.map_resource_publishers)', Object.keys(this.map_resource_publishers));
|
|
269
|
-
} else {
|
|
270
|
-
// if its a function
|
|
271
|
-
// return that function call to the response.
|
|
272
|
-
let t_item = typeof item;
|
|
273
|
-
if (t_item === "function") {
|
|
274
|
-
// Function_Call_Publisher
|
|
275
|
-
// could respec this.
|
|
276
|
-
|
|
277
|
-
// And the Function_Publisher operates through the Publisher API. Not sure what that is right now though.
|
|
278
|
-
// directly attaching the resource publishers?
|
|
279
|
-
let pub = new Function_Publisher({
|
|
280
|
-
fn: item,
|
|
281
|
-
schema: schema
|
|
282
|
-
});
|
|
283
|
-
this.map_resource_publishers[published_name] = pub;
|
|
284
|
-
//
|
|
285
|
-
|
|
286
|
-
} else {
|
|
287
|
-
if (item.next && item.complete && item.error) {
|
|
288
|
-
let obs_pub = new Observable_Publisher({
|
|
289
|
-
obs: item,
|
|
290
|
-
schema: schema
|
|
291
|
-
});
|
|
292
|
-
this.map_resource_publishers[published_name] = obs_pub;
|
|
293
|
-
} else {
|
|
294
|
-
console.log("item", item);
|
|
295
|
-
throw "Unrecognised item type. Possibly node module versions are wrong / have not been linked fully.";
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
//if (item instanceof Evented_Class) {
|
|
299
|
-
}
|
|
300
|
-
};
|
|
301
|
-
|
|
302
|
-
if (sig === "[o]") {
|
|
303
|
-
each(a[0], (v, i) => {
|
|
304
|
-
single(i, v);
|
|
305
|
-
})
|
|
306
|
-
} else {
|
|
307
|
-
|
|
308
|
-
single(published_name, item);
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
get resource_names() {
|
|
313
|
-
//console.log('this.resource_pool', this.resource_pool);
|
|
314
|
-
return this.resource_pool.resource_names;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
get_resource(resource_name) {
|
|
318
|
-
var resource_pool = this.resource_pool;
|
|
319
|
-
//console.log('resource_pool', resource_pool);
|
|
320
|
-
|
|
321
|
-
//console.log('this._.resource_pool', this._.resource_pool);
|
|
322
|
-
|
|
323
|
-
//throw 'stop';
|
|
324
|
-
return resource_pool.get_resource(resource_name);
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
get def_resource_publishers() {
|
|
328
|
-
const res = {};
|
|
329
|
-
each(this.map_resource_publishers, (rp, name) => {
|
|
330
|
-
|
|
331
|
-
let def = {
|
|
332
|
-
name: name,
|
|
333
|
-
type: rp.type
|
|
334
|
-
}
|
|
335
|
-
res[name] = def;
|
|
336
|
-
if (rp.type === 'function') {
|
|
337
|
-
if (rp.schema) def.schema = rp.schema;
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
})
|
|
341
|
-
|
|
342
|
-
return res;
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
start(callback) {
|
|
346
|
-
var resource_pool = this.resource_pool;
|
|
347
|
-
resource_pool.start(callback);
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
meets_requirements() {
|
|
351
|
-
// Likely will be part of Status
|
|
352
|
-
|
|
353
|
-
//return false;
|
|
354
|
-
|
|
355
|
-
return true;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
// Needs to be able to process HTTP requests. A bit like the Router in that way.
|
|
359
|
-
process(req, res) {
|
|
360
|
-
//console.log('website process request req.url', req.url);
|
|
361
|
-
//throw 'stop';
|
|
362
|
-
|
|
363
|
-
var remoteAddress = req.connection.remoteAddress;
|
|
364
|
-
var router = this.router;
|
|
365
|
-
var res_process = router.process(req, res);
|
|
366
|
-
if (res_process === false) {
|
|
367
|
-
if (req.url === "/") {
|
|
368
|
-
// Send this to the static HTML processing system.
|
|
369
|
-
|
|
370
|
-
var static_html_resource = this.resource_pool.get_resource(
|
|
371
|
-
"Static HTML"
|
|
372
|
-
);
|
|
373
|
-
//console.log('static_html_resource', static_html_resource);
|
|
374
|
-
// And lets get the static resource to process it
|
|
375
|
-
if (static_html_resource) {
|
|
376
|
-
static_html_resource.process(req, res);
|
|
377
|
-
}
|
|
378
|
-
} else {
|
|
379
|
-
// show a 404
|
|
380
|
-
res.writeHead(404, {
|
|
381
|
-
"Content-Type": "text/plain"
|
|
382
|
-
});
|
|
383
|
-
res.write("404 Not Found\n");
|
|
384
|
-
res.end();
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
module.exports = Website_Resource;
|
|
1
|
+
/**
|
|
2
|
+
* Created by James on 29/07/2014.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// Want to get the core resources working and tested.
|
|
6
|
+
// Want to run a clock website / service to start with.
|
|
7
|
+
// The server could have a clock, while clients could connect to it and share the information.
|
|
8
|
+
// Could also experiment with P2P distribution of the data.
|
|
9
|
+
// A clock is also useful because it contains time signals so we can see how long it takes for data to reach various machines.
|
|
10
|
+
|
|
11
|
+
// A web resource in particular?
|
|
12
|
+
// Any need for an HTML resource?
|
|
13
|
+
// Probably not - have web resource handle HTML and websockets.
|
|
14
|
+
|
|
15
|
+
// Resources could also have events which objects can listen to.
|
|
16
|
+
// Programmatic objects can listen.
|
|
17
|
+
// The resources may broadcast to whatever is listening.
|
|
18
|
+
|
|
19
|
+
// Also, maintaining one connection stream, communicating with multiple resources - could connect through a Resource Pool, or maybe there
|
|
20
|
+
// could be a Multi Resource Publisher that publishes a bunch of resources.
|
|
21
|
+
|
|
22
|
+
// The Application router at the moment sending requests to resources.
|
|
23
|
+
// I am thinking that rather than doing that, the requests should be handled by a resource publisher that interacts with the resource and publishes it over HTTP.
|
|
24
|
+
|
|
25
|
+
// Resources in general won't handle HTTP requests, though they will have the capability.
|
|
26
|
+
// More likely that a resource, when it is served online, will be served using a Resource Publisher (which is itself a resource), which handles HTTP implementation details that would otherwise have
|
|
27
|
+
// to be repeated between resources.
|
|
28
|
+
|
|
29
|
+
//define(["./jsgui-lang-util", './abstract-resource'], function(jsgui, AR) {
|
|
30
|
+
|
|
31
|
+
// Do this not with AMD?
|
|
32
|
+
|
|
33
|
+
// May need Website_Data_Resource
|
|
34
|
+
// Would be configured within the node app, client has maximum autoconfig from connecting to the server, and integration with client-side controls.
|
|
35
|
+
// With the DB admin, it's about returining queries (maybe from RAM) about table data.
|
|
36
|
+
// /data/then the api?
|
|
37
|
+
|
|
38
|
+
// Respond to both data HTTP requests and websocket connections.
|
|
39
|
+
|
|
40
|
+
// HTTP data request -> response seems like the most important step now.
|
|
41
|
+
|
|
42
|
+
// An fs Resource would be of use for file system browser.
|
|
43
|
+
// Could have a client-side fs resource that connects to a veriety of services, could have one that connects to the server-side fs resource.
|
|
44
|
+
|
|
45
|
+
// Need to connect a data-providing resource to the UI component in cases where it's not secure to do so automatically.
|
|
46
|
+
// It would be much more secure to bring up an NTP provision service automatically than a file system one. Don't want to take that risk now.
|
|
47
|
+
//
|
|
48
|
+
|
|
49
|
+
var Site_Images = require("./website-image-resource");
|
|
50
|
+
|
|
51
|
+
//console.log('1) Site_Images', Site_Images);
|
|
52
|
+
|
|
53
|
+
var jsgui = require("jsgui3-html");
|
|
54
|
+
const { each, get_a_sig, is_defined, tof } = jsgui;
|
|
55
|
+
|
|
56
|
+
//var Web_Resource = require('./website-resource');
|
|
57
|
+
const Resource = jsgui.Resource;
|
|
58
|
+
const Router = jsgui.Router;
|
|
59
|
+
//const Evented_Class = jsgui.Evented_Class;
|
|
60
|
+
|
|
61
|
+
var Resource_Pool = require("./server-resource-pool");
|
|
62
|
+
//var Resource_Web_Admin = require('../web-admin');
|
|
63
|
+
|
|
64
|
+
var Site_JavaScript = require("./website-javascript-resource");
|
|
65
|
+
//console.log('1) Site_JavaScript', Site_JavaScript);
|
|
66
|
+
var Site_CSS = require("./website-css-resource");
|
|
67
|
+
var Site_Static_HTML = require("./website-static-html-resource");
|
|
68
|
+
//var DB_Web_Resource = require('../../web/db-resource-postgres');
|
|
69
|
+
//var database_resource_factory = require('../../db/resource/factory');
|
|
70
|
+
|
|
71
|
+
const Resource_Publisher = require("../publishing/resource-publisher");
|
|
72
|
+
const Observable_Publisher = require("../publishing/observable-publisher");
|
|
73
|
+
const Function_Publisher = require("../publishing/function-publisher");
|
|
74
|
+
//const Data_Resource = require("./data-resource");
|
|
75
|
+
|
|
76
|
+
class Website_Resource extends Resource {
|
|
77
|
+
constructor(spec = {}) {
|
|
78
|
+
super(spec);
|
|
79
|
+
// A bit of a special resource here because it has its own resource_pool.
|
|
80
|
+
var resource_pool = new Resource_Pool({
|
|
81
|
+
name: "Website Resource Pool"
|
|
82
|
+
});
|
|
83
|
+
this.resource_pool = resource_pool;
|
|
84
|
+
var database_spec = spec.database;
|
|
85
|
+
var web_database_resource;
|
|
86
|
+
|
|
87
|
+
if (database_spec) {
|
|
88
|
+
database_spec.name = database_spec.name || database_spec.database_name;
|
|
89
|
+
var database_resource = database_resource_factory(database_spec);
|
|
90
|
+
database_resource.start();
|
|
91
|
+
// should start automatically when in the pool?
|
|
92
|
+
// does the pool need to be told to start?
|
|
93
|
+
// Though probably don't want to start the resource on initialization.
|
|
94
|
+
resource_pool.add(database_resource);
|
|
95
|
+
web_database_resource = new DB_Web_Resource({
|
|
96
|
+
database: database_resource,
|
|
97
|
+
meta: {
|
|
98
|
+
name: "Web DB",
|
|
99
|
+
pool: resource_pool
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (web_database_resource) {
|
|
105
|
+
resource_pool.add(web_database_resource);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
var router = new Router({
|
|
109
|
+
name: "Site Router"
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
this.router = router;
|
|
113
|
+
|
|
114
|
+
var spec_web_admin = {
|
|
115
|
+
//'web_database': web_database_resource,
|
|
116
|
+
meta: {
|
|
117
|
+
name: "Web Admin"
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
if (web_database_resource) {
|
|
122
|
+
spec_web_admin.web_database = web_database_resource;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
var img_resource = new Site_Images({
|
|
126
|
+
//'meta': {
|
|
127
|
+
name: "Site Images",
|
|
128
|
+
pool: resource_pool
|
|
129
|
+
// }
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
var js_resource = new Site_JavaScript({
|
|
133
|
+
//'meta': {
|
|
134
|
+
name: "Site JavaScript",
|
|
135
|
+
pool: resource_pool
|
|
136
|
+
//}
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
// Also want a static HTML server.
|
|
140
|
+
// Would serve index.html by default I think???
|
|
141
|
+
// Probably with the static or simplest settings.
|
|
142
|
+
|
|
143
|
+
var static_html_resource;
|
|
144
|
+
|
|
145
|
+
if (spec == "static") {
|
|
146
|
+
static_html_resource = new Site_Static_HTML({
|
|
147
|
+
//'meta': {
|
|
148
|
+
name: "Static HTML",
|
|
149
|
+
pool: resource_pool
|
|
150
|
+
//}
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
resource_pool.push(static_html_resource);
|
|
154
|
+
|
|
155
|
+
// Perhaps set it up with the specific files (automatically)?
|
|
156
|
+
// Probably with the index.html
|
|
157
|
+
}
|
|
158
|
+
var css_resource = new Site_CSS({
|
|
159
|
+
//'meta': {
|
|
160
|
+
name: "Site CSS",
|
|
161
|
+
pool: resource_pool
|
|
162
|
+
//}
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
js_resource.on('extracted-controls-css', str_extracted_css => {
|
|
167
|
+
css_resource.serve_str_css('controls.css', str_extracted_css);
|
|
168
|
+
// Will serve this as controls.css
|
|
169
|
+
// Separate HTTP request, will get more CSS for the moment.
|
|
170
|
+
|
|
171
|
+
});
|
|
172
|
+
// javascript and css resources.
|
|
173
|
+
resource_pool.push(router);
|
|
174
|
+
resource_pool.push(img_resource);
|
|
175
|
+
resource_pool.push(js_resource);
|
|
176
|
+
resource_pool.push(css_resource);
|
|
177
|
+
//resource_pool.push(data_resource);
|
|
178
|
+
|
|
179
|
+
// anything ending in .css as well.
|
|
180
|
+
// Routing maybe wouldn't work like that.
|
|
181
|
+
//router.set_route('*.css', css_resource, css_resource.process);
|
|
182
|
+
|
|
183
|
+
router.set_route("css/*", css_resource, css_resource.process);
|
|
184
|
+
router.set_route("js/*", js_resource, js_resource.process);
|
|
185
|
+
// As well as this, it could get the JavaScript resource to serve the JavaScript from the app's js directory.
|
|
186
|
+
js_resource.serve_directory("js");
|
|
187
|
+
router.set_route("img/*", img_resource, img_resource.process);
|
|
188
|
+
router.set_route("images/*", img_resource, img_resource.process);
|
|
189
|
+
this.map_resource_publishers = this.map_resource_publishers || {};
|
|
190
|
+
router.set_route("resources/:resource_name/*", this, (req, res) => {
|
|
191
|
+
let { url, method } = req;
|
|
192
|
+
let s_url = url.split("/");
|
|
193
|
+
let resource_short_name = s_url[2];
|
|
194
|
+
let resource_publisher = this.map_resource_publishers[resource_short_name];
|
|
195
|
+
if (resource_publisher) {
|
|
196
|
+
resource_publisher.handle_http(req, res);
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
if (!is_defined(spec)) spec = {};
|
|
200
|
+
this.resource_pool = resource_pool;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
publishing_get_pub(item) {
|
|
204
|
+
let pub;
|
|
205
|
+
if (item instanceof jsgui.Resource) {
|
|
206
|
+
pub = new Resource_Publisher({
|
|
207
|
+
resource: item
|
|
208
|
+
});
|
|
209
|
+
} else {
|
|
210
|
+
// if its a function
|
|
211
|
+
// return that function call to the response.
|
|
212
|
+
let t_item = typeof item;
|
|
213
|
+
if (t_item === "function") {
|
|
214
|
+
// Function_Call_Publisher
|
|
215
|
+
// could respec this.
|
|
216
|
+
// And the Function_Publisher operates through the Publisher API. Not sure what that is right now though.
|
|
217
|
+
|
|
218
|
+
pub = new Function_Publisher({
|
|
219
|
+
fn: item
|
|
220
|
+
});
|
|
221
|
+
//this.map_resource_publishers[published_name] = pub;
|
|
222
|
+
//
|
|
223
|
+
} else {
|
|
224
|
+
if (item.next && item.complete && item.error) {
|
|
225
|
+
// assuming observable
|
|
226
|
+
// Observable publisher
|
|
227
|
+
// One way sending...
|
|
228
|
+
//console.log('using Observable_Publisher');
|
|
229
|
+
pub = new Observable_Publisher({
|
|
230
|
+
obs: item
|
|
231
|
+
});
|
|
232
|
+
// or not a resource publisher, an observable publisher.
|
|
233
|
+
//this.map_resource_publishers = this.map_resource_publishers || {};
|
|
234
|
+
//this.map_resource_publishers[published_name] = obs_pub;
|
|
235
|
+
|
|
236
|
+
//console.log('2) this', this);
|
|
237
|
+
//console.log('this.map_resource_publishers', this.map_resource_publishers);
|
|
238
|
+
//console.trace();
|
|
239
|
+
} else {
|
|
240
|
+
console.log("item", item);
|
|
241
|
+
throw "Unrecognised item type. Possibly node module versions are wrong / have not been linked fully.";
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
//if (item instanceof Evented_Class) {
|
|
245
|
+
}
|
|
246
|
+
return pub;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// publish within resources?
|
|
250
|
+
publish(published_name, item, schema) {
|
|
251
|
+
let sig = get_a_sig(arguments),
|
|
252
|
+
a = arguments,
|
|
253
|
+
l = a.length;
|
|
254
|
+
const single = (published_name, item) => {
|
|
255
|
+
if (item instanceof jsgui.Resource) {
|
|
256
|
+
let resource_publisher = new Resource_Publisher({
|
|
257
|
+
resource: item,
|
|
258
|
+
name: published_name
|
|
259
|
+
});
|
|
260
|
+
this.map_resource_publishers[published_name] = resource_publisher;
|
|
261
|
+
|
|
262
|
+
item.name = item.name || published_name;
|
|
263
|
+
// add that resource!
|
|
264
|
+
// (to the pool?)
|
|
265
|
+
//console.log('item', item);
|
|
266
|
+
this.resource_pool.add(item);
|
|
267
|
+
|
|
268
|
+
//console.log('Object.keys(this.map_resource_publishers)', Object.keys(this.map_resource_publishers));
|
|
269
|
+
} else {
|
|
270
|
+
// if its a function
|
|
271
|
+
// return that function call to the response.
|
|
272
|
+
let t_item = typeof item;
|
|
273
|
+
if (t_item === "function") {
|
|
274
|
+
// Function_Call_Publisher
|
|
275
|
+
// could respec this.
|
|
276
|
+
|
|
277
|
+
// And the Function_Publisher operates through the Publisher API. Not sure what that is right now though.
|
|
278
|
+
// directly attaching the resource publishers?
|
|
279
|
+
let pub = new Function_Publisher({
|
|
280
|
+
fn: item,
|
|
281
|
+
schema: schema
|
|
282
|
+
});
|
|
283
|
+
this.map_resource_publishers[published_name] = pub;
|
|
284
|
+
//
|
|
285
|
+
|
|
286
|
+
} else {
|
|
287
|
+
if (item.next && item.complete && item.error) {
|
|
288
|
+
let obs_pub = new Observable_Publisher({
|
|
289
|
+
obs: item,
|
|
290
|
+
schema: schema
|
|
291
|
+
});
|
|
292
|
+
this.map_resource_publishers[published_name] = obs_pub;
|
|
293
|
+
} else {
|
|
294
|
+
console.log("item", item);
|
|
295
|
+
throw "Unrecognised item type. Possibly node module versions are wrong / have not been linked fully.";
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
//if (item instanceof Evented_Class) {
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
if (sig === "[o]") {
|
|
303
|
+
each(a[0], (v, i) => {
|
|
304
|
+
single(i, v);
|
|
305
|
+
})
|
|
306
|
+
} else {
|
|
307
|
+
|
|
308
|
+
single(published_name, item);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
get resource_names() {
|
|
313
|
+
//console.log('this.resource_pool', this.resource_pool);
|
|
314
|
+
return this.resource_pool.resource_names;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
get_resource(resource_name) {
|
|
318
|
+
var resource_pool = this.resource_pool;
|
|
319
|
+
//console.log('resource_pool', resource_pool);
|
|
320
|
+
|
|
321
|
+
//console.log('this._.resource_pool', this._.resource_pool);
|
|
322
|
+
|
|
323
|
+
//throw 'stop';
|
|
324
|
+
return resource_pool.get_resource(resource_name);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
get def_resource_publishers() {
|
|
328
|
+
const res = {};
|
|
329
|
+
each(this.map_resource_publishers, (rp, name) => {
|
|
330
|
+
|
|
331
|
+
let def = {
|
|
332
|
+
name: name,
|
|
333
|
+
type: rp.type
|
|
334
|
+
}
|
|
335
|
+
res[name] = def;
|
|
336
|
+
if (rp.type === 'function') {
|
|
337
|
+
if (rp.schema) def.schema = rp.schema;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
})
|
|
341
|
+
|
|
342
|
+
return res;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
start(callback) {
|
|
346
|
+
var resource_pool = this.resource_pool;
|
|
347
|
+
resource_pool.start(callback);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
meets_requirements() {
|
|
351
|
+
// Likely will be part of Status
|
|
352
|
+
|
|
353
|
+
//return false;
|
|
354
|
+
|
|
355
|
+
return true;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// Needs to be able to process HTTP requests. A bit like the Router in that way.
|
|
359
|
+
process(req, res) {
|
|
360
|
+
//console.log('website process request req.url', req.url);
|
|
361
|
+
//throw 'stop';
|
|
362
|
+
|
|
363
|
+
var remoteAddress = req.connection.remoteAddress;
|
|
364
|
+
var router = this.router;
|
|
365
|
+
var res_process = router.process(req, res);
|
|
366
|
+
if (res_process === false) {
|
|
367
|
+
if (req.url === "/") {
|
|
368
|
+
// Send this to the static HTML processing system.
|
|
369
|
+
|
|
370
|
+
var static_html_resource = this.resource_pool.get_resource(
|
|
371
|
+
"Static HTML"
|
|
372
|
+
);
|
|
373
|
+
//console.log('static_html_resource', static_html_resource);
|
|
374
|
+
// And lets get the static resource to process it
|
|
375
|
+
if (static_html_resource) {
|
|
376
|
+
static_html_resource.process(req, res);
|
|
377
|
+
}
|
|
378
|
+
} else {
|
|
379
|
+
// show a 404
|
|
380
|
+
res.writeHead(404, {
|
|
381
|
+
"Content-Type": "text/plain"
|
|
382
|
+
});
|
|
383
|
+
res.write("404 Not Found\n");
|
|
384
|
+
res.end();
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
module.exports = Website_Resource;
|