jsgui3-server 0.0.150 → 0.0.151
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/.github/instructions/copilot.instructions.md +1 -0
- package/AGENTS.md +2 -0
- package/README.md +68 -13
- package/admin-ui/v1/controls/admin_shell.js +669 -669
- package/docs/api-reference.md +383 -303
- package/docs/books/creating-a-new-admin-ui/README.md +20 -20
- package/docs/comprehensive-documentation.md +220 -220
- package/docs/configuration-reference.md +227 -204
- package/docs/middleware-guide.md +236 -0
- package/docs/system-architecture.md +24 -18
- package/middleware/compression.js +217 -0
- package/middleware/index.js +15 -0
- package/module.js +3 -0
- package/package.json +1 -1
- package/serve-factory.js +28 -0
- package/server.js +81 -20
package/docs/api-reference.md
CHANGED
|
@@ -32,30 +32,30 @@ Server.serve(options?: ServerOptions): Promise<Server>
|
|
|
32
32
|
- `DiscoveryError`: Cannot find client files or controls
|
|
33
33
|
- `BindingError`: Cannot bind to specified host/port
|
|
34
34
|
|
|
35
|
-
**Example:**
|
|
36
|
-
```javascript
|
|
37
|
-
const server = await Server.serve({
|
|
38
|
-
port: 3000,
|
|
39
|
-
ctrl: MyControl,
|
|
40
|
-
resources: {
|
|
41
|
-
worker_direct: {
|
|
42
|
-
type: 'process',
|
|
43
|
-
command: process.execPath,
|
|
44
|
-
args: ['worker.js']
|
|
45
|
-
},
|
|
46
|
-
remote_worker: {
|
|
47
|
-
type: 'remote',
|
|
48
|
-
host: '127.0.0.1',
|
|
49
|
-
port: 3400
|
|
50
|
-
}
|
|
51
|
-
},
|
|
52
|
-
events: true
|
|
53
|
-
});
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
**Serve-specific options:**
|
|
57
|
-
- `resources`: Registers managed resources (in-process resource objects, local process resources, remote HTTP process resources).
|
|
58
|
-
- `events`: Enables built-in SSE publisher for resource lifecycle events (`/events` by default).
|
|
35
|
+
**Example:**
|
|
36
|
+
```javascript
|
|
37
|
+
const server = await Server.serve({
|
|
38
|
+
port: 3000,
|
|
39
|
+
ctrl: MyControl,
|
|
40
|
+
resources: {
|
|
41
|
+
worker_direct: {
|
|
42
|
+
type: 'process',
|
|
43
|
+
command: process.execPath,
|
|
44
|
+
args: ['worker.js']
|
|
45
|
+
},
|
|
46
|
+
remote_worker: {
|
|
47
|
+
type: 'remote',
|
|
48
|
+
host: '127.0.0.1',
|
|
49
|
+
port: 3400
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
events: true
|
|
53
|
+
});
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
**Serve-specific options:**
|
|
57
|
+
- `resources`: Registers managed resources (in-process resource objects, local process resources, remote HTTP process resources).
|
|
58
|
+
- `events`: Enables built-in SSE publisher for resource lifecycle events (`/events` by default).
|
|
59
59
|
|
|
60
60
|
### Server Constructor
|
|
61
61
|
|
|
@@ -71,27 +71,27 @@ new Server(options?: ServerOptions)
|
|
|
71
71
|
|
|
72
72
|
**Returns:** Server instance
|
|
73
73
|
|
|
74
|
-
**Events:**
|
|
75
|
-
- `'ready'`: Emitted when bundling is complete
|
|
76
|
-
- `'started'`: Emitted when HTTP server is listening
|
|
77
|
-
- `'error'`: Emitted on server errors
|
|
78
|
-
|
|
79
|
-
### Module Exports
|
|
80
|
-
|
|
81
|
-
```javascript
|
|
82
|
-
const jsgui = require('jsgui3-server');
|
|
83
|
-
|
|
84
|
-
// Top-level exports
|
|
85
|
-
jsgui.Process_Resource;
|
|
86
|
-
jsgui.Remote_Process_Resource;
|
|
87
|
-
jsgui.HTTP_SSE_Publisher;
|
|
88
|
-
|
|
89
|
-
// Resource namespace aliases
|
|
90
|
-
jsgui.Resource.Process;
|
|
91
|
-
jsgui.Resource.Remote_Process;
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
## Server Instance Methods
|
|
74
|
+
**Events:**
|
|
75
|
+
- `'ready'`: Emitted when bundling is complete
|
|
76
|
+
- `'started'`: Emitted when HTTP server is listening
|
|
77
|
+
- `'error'`: Emitted on server errors
|
|
78
|
+
|
|
79
|
+
### Module Exports
|
|
80
|
+
|
|
81
|
+
```javascript
|
|
82
|
+
const jsgui = require('jsgui3-server');
|
|
83
|
+
|
|
84
|
+
// Top-level exports
|
|
85
|
+
jsgui.Process_Resource;
|
|
86
|
+
jsgui.Remote_Process_Resource;
|
|
87
|
+
jsgui.HTTP_SSE_Publisher;
|
|
88
|
+
|
|
89
|
+
// Resource namespace aliases
|
|
90
|
+
jsgui.Resource.Process;
|
|
91
|
+
jsgui.Resource.Remote_Process;
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Server Instance Methods
|
|
95
95
|
|
|
96
96
|
### server.start(port, callback)
|
|
97
97
|
|
|
@@ -106,7 +106,7 @@ server.start(port?: number, callback?: (err?: Error) => void): void
|
|
|
106
106
|
- `port` (number, optional): Port to listen on (default: 8080)
|
|
107
107
|
- `callback` (function, optional): Called when server starts or fails
|
|
108
108
|
|
|
109
|
-
### server.publish(route, handler)
|
|
109
|
+
### server.publish(route, handler)
|
|
110
110
|
|
|
111
111
|
Adds an API endpoint (legacy API).
|
|
112
112
|
|
|
@@ -115,53 +115,127 @@ Adds an API endpoint (legacy API).
|
|
|
115
115
|
server.publish(route: string, handler: Function): void
|
|
116
116
|
```
|
|
117
117
|
|
|
118
|
-
**Parameters:**
|
|
119
|
-
- `route` (string): Route path (automatically prefixed with `/api/`)
|
|
120
|
-
- `handler` (Function): Request handler function
|
|
121
|
-
|
|
122
|
-
### server.publish_observable(route, observable, options)
|
|
123
|
-
|
|
124
|
-
Adds an observable-backed SSE endpoint.
|
|
125
|
-
|
|
126
|
-
**Signature:**
|
|
127
|
-
```javascript
|
|
128
|
-
server.publish_observable(route: string, observable: Observable, options?: object): HTTP_Observable_Publisher
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
**Parameters:**
|
|
132
|
-
- `route` (string): Route path. If it does not start with `/`, it is prefixed with `/api/`.
|
|
133
|
-
- `observable` (Observable): Source observable stream.
|
|
134
|
-
- `options` (object, optional): Publisher options.
|
|
135
|
-
|
|
136
|
-
**Returns:** `HTTP_Observable_Publisher` instance.
|
|
137
|
-
|
|
138
|
-
**Alias:** `server.publishObservable(route, observable, options)`
|
|
139
|
-
|
|
140
|
-
### server.close(callback)
|
|
141
|
-
|
|
142
|
-
Stops managed resources and closes all bound HTTP servers.
|
|
143
|
-
|
|
144
|
-
**Signature:**
|
|
145
|
-
```javascript
|
|
146
|
-
server.close(callback?: (err?: Error | null) => void): void
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
**Behavior:**
|
|
150
|
-
- Calls `resource_pool.stop()` when available
|
|
151
|
-
- Stops `sse_publisher` when present
|
|
152
|
-
- Closes all HTTP listeners
|
|
153
|
-
|
|
154
|
-
### server.use(
|
|
155
|
-
|
|
156
|
-
|
|
118
|
+
**Parameters:**
|
|
119
|
+
- `route` (string): Route path (automatically prefixed with `/api/`)
|
|
120
|
+
- `handler` (Function): Request handler function
|
|
121
|
+
|
|
122
|
+
### server.publish_observable(route, observable, options)
|
|
123
|
+
|
|
124
|
+
Adds an observable-backed SSE endpoint.
|
|
125
|
+
|
|
126
|
+
**Signature:**
|
|
127
|
+
```javascript
|
|
128
|
+
server.publish_observable(route: string, observable: Observable, options?: object): HTTP_Observable_Publisher
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
**Parameters:**
|
|
132
|
+
- `route` (string): Route path. If it does not start with `/`, it is prefixed with `/api/`.
|
|
133
|
+
- `observable` (Observable): Source observable stream.
|
|
134
|
+
- `options` (object, optional): Publisher options.
|
|
135
|
+
|
|
136
|
+
**Returns:** `HTTP_Observable_Publisher` instance.
|
|
137
|
+
|
|
138
|
+
**Alias:** `server.publishObservable(route, observable, options)`
|
|
139
|
+
|
|
140
|
+
### server.close(callback)
|
|
141
|
+
|
|
142
|
+
Stops managed resources and closes all bound HTTP servers.
|
|
143
|
+
|
|
144
|
+
**Signature:**
|
|
145
|
+
```javascript
|
|
146
|
+
server.close(callback?: (err?: Error | null) => void): void
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
**Behavior:**
|
|
150
|
+
- Calls `resource_pool.stop()` when available
|
|
151
|
+
- Stops `sse_publisher` when present
|
|
152
|
+
- Closes all HTTP listeners
|
|
153
|
+
|
|
154
|
+
### server.use(fn)
|
|
155
|
+
|
|
156
|
+
Register middleware to run before every request is routed. Middleware is executed
|
|
157
|
+
in registration order. The chain runs to completion before the router processes
|
|
158
|
+
the request.
|
|
157
159
|
|
|
158
160
|
**Signature:**
|
|
159
161
|
```javascript
|
|
160
|
-
server.use(
|
|
162
|
+
server.use(fn: Function): Server // returns `this` for chaining
|
|
161
163
|
```
|
|
162
164
|
|
|
163
165
|
**Parameters:**
|
|
164
|
-
- `
|
|
166
|
+
- `fn` (Function): Middleware function with signature `(req, res, next) => void`
|
|
167
|
+
- `req` — Node.js `http.IncomingMessage`
|
|
168
|
+
- `res` — Node.js `http.ServerResponse`
|
|
169
|
+
- `next` — Call `next()` to continue to the next middleware / router.
|
|
170
|
+
Call `next(err)` to skip remaining middleware and trigger the error handler
|
|
171
|
+
(500 response).
|
|
172
|
+
|
|
173
|
+
**Returns:** The server instance (for chaining).
|
|
174
|
+
|
|
175
|
+
**Throws:** `Error` if `fn` is not a function.
|
|
176
|
+
|
|
177
|
+
**Example:**
|
|
178
|
+
```javascript
|
|
179
|
+
const { compression } = require('jsgui3-server/middleware');
|
|
180
|
+
|
|
181
|
+
server
|
|
182
|
+
.use((req, res, next) => {
|
|
183
|
+
console.log(`${req.method} ${req.url}`);
|
|
184
|
+
next();
|
|
185
|
+
})
|
|
186
|
+
.use(compression());
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
**Execution order:**
|
|
190
|
+
```
|
|
191
|
+
HTTP Request → middleware[0] → middleware[1] → … → router
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
If no middleware is registered, the router is called directly with zero overhead.
|
|
195
|
+
|
|
196
|
+
**See also:** [Middleware Guide](middleware-guide.md) for response-wrapping
|
|
197
|
+
patterns, custom middleware examples, and the built-in compression reference.
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
### Built-in Middleware
|
|
202
|
+
|
|
203
|
+
#### `compression([options])`
|
|
204
|
+
|
|
205
|
+
Response-compression middleware. Transparently compresses response bodies
|
|
206
|
+
(gzip / deflate / brotli) when the client supports it and the content type
|
|
207
|
+
is compressible.
|
|
208
|
+
|
|
209
|
+
```javascript
|
|
210
|
+
const { compression } = require('jsgui3-server/middleware');
|
|
211
|
+
server.use(compression()); // defaults
|
|
212
|
+
server.use(compression({ threshold: 512 })); // lower threshold
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
**Options:**
|
|
216
|
+
|
|
217
|
+
| Option | Type | Default | Description |
|
|
218
|
+
|-----------|--------|---------------------------|-------------------------------------------|
|
|
219
|
+
| `threshold` | number | `1024` | Minimum body size in bytes to compress |
|
|
220
|
+
| `level` | number | `Z_DEFAULT_COMPRESSION` | zlib compression level (1–9, or -1) |
|
|
221
|
+
|
|
222
|
+
**Encoding priority:** gzip → deflate → brotli
|
|
223
|
+
|
|
224
|
+
**Compressible types:** `application/json`, `text/html`, `text/plain`,
|
|
225
|
+
`text/css`, `text/xml`, `text/csv`, `text/javascript`,
|
|
226
|
+
`application/javascript`, `application/xml`, `application/xhtml+xml`,
|
|
227
|
+
`application/manifest+json`, `image/svg+xml`.
|
|
228
|
+
|
|
229
|
+
**Not compressed:** bodies below threshold, binary content types, responses
|
|
230
|
+
with an existing `Content-Encoding`, and streaming responses (`res.write()`
|
|
231
|
+
before `res.end()` — e.g. SSE).
|
|
232
|
+
|
|
233
|
+
**Access paths:**
|
|
234
|
+
```javascript
|
|
235
|
+
require('jsgui3-server/middleware').compression // direct
|
|
236
|
+
require('jsgui3-server').middleware.compression // via module
|
|
237
|
+
Server.middleware.compression // via class
|
|
238
|
+
```
|
|
165
239
|
|
|
166
240
|
## Port Utilities
|
|
167
241
|
|
|
@@ -507,7 +581,7 @@ Serves CSS files.
|
|
|
507
581
|
serve(request: IncomingMessage, response: ServerResponse): Promise<void>
|
|
508
582
|
```
|
|
509
583
|
|
|
510
|
-
### HTTP_API_Publisher
|
|
584
|
+
### HTTP_API_Publisher
|
|
511
585
|
|
|
512
586
|
Handles API endpoints.
|
|
513
587
|
|
|
@@ -525,162 +599,162 @@ new HTTP_API_Publisher(spec?: PublisherSpec)
|
|
|
525
599
|
Handles API requests.
|
|
526
600
|
|
|
527
601
|
**Signature:**
|
|
528
|
-
```javascript
|
|
529
|
-
serve(request: IncomingMessage, response: ServerResponse): Promise<void>
|
|
530
|
-
```
|
|
531
|
-
|
|
532
|
-
### HTTP_SSE_Publisher
|
|
533
|
-
|
|
534
|
-
General-purpose SSE publisher for explicit event fan-out.
|
|
535
|
-
|
|
536
|
-
**Extends:** `HTTP_Publisher`
|
|
537
|
-
|
|
538
|
-
**Constructor:**
|
|
539
|
-
```javascript
|
|
540
|
-
new HTTP_SSE_Publisher(spec?: {
|
|
541
|
-
name?: string,
|
|
542
|
-
keepaliveIntervalMs?: number,
|
|
543
|
-
maxClients?: number,
|
|
544
|
-
eventHistorySize?: number
|
|
545
|
-
})
|
|
546
|
-
```
|
|
547
|
-
|
|
548
|
-
**Methods:**
|
|
549
|
-
- `handle_http(req, res)`
|
|
550
|
-
- `broadcast(event_name, data_value)`
|
|
551
|
-
- `send(client_id, event_name, data_value)`
|
|
552
|
-
- `stop(callback?)`
|
|
553
|
-
|
|
554
|
-
**Properties:**
|
|
555
|
-
- `client_count` (number)
|
|
556
|
-
|
|
557
|
-
## Resource Classes
|
|
558
|
-
|
|
559
|
-
### Process_Resource
|
|
560
|
-
|
|
561
|
-
Represents a local process as a resource with a unified lifecycle API.
|
|
562
|
-
|
|
563
|
-
**Extends:** `Resource`
|
|
564
|
-
|
|
565
|
-
**Constructor:**
|
|
566
|
-
```javascript
|
|
567
|
-
new Process_Resource(spec?: {
|
|
568
|
-
name?: string,
|
|
569
|
-
command?: string,
|
|
570
|
-
args?: string[],
|
|
571
|
-
cwd?: string,
|
|
572
|
-
env?: object,
|
|
573
|
-
autoRestart?: boolean,
|
|
574
|
-
maxRestarts?: number,
|
|
575
|
-
processManager?: 'direct' | {
|
|
576
|
-
type: 'direct' | 'pm2',
|
|
577
|
-
pm2Path?: string,
|
|
578
|
-
ecosystem?: string
|
|
579
|
-
},
|
|
580
|
-
healthCheck?: {
|
|
581
|
-
type: 'http' | 'tcp' | 'custom',
|
|
582
|
-
url?: string,
|
|
583
|
-
host?: string,
|
|
584
|
-
port?: number,
|
|
585
|
-
fn?: Function,
|
|
586
|
-
intervalMs?: number,
|
|
587
|
-
timeoutMs?: number,
|
|
588
|
-
failuresBeforeUnhealthy?: number
|
|
589
|
-
}
|
|
590
|
-
})
|
|
591
|
-
```
|
|
592
|
-
|
|
593
|
-
**Core Methods:**
|
|
594
|
-
- `start(callback?)`
|
|
595
|
-
- `stop(callback?)`
|
|
596
|
-
- `restart(callback?)`
|
|
597
|
-
- `get_abstract()`
|
|
598
|
-
|
|
599
|
-
**Status:**
|
|
600
|
-
```javascript
|
|
601
|
-
{
|
|
602
|
-
state: 'stopped' | 'starting' | 'running' | 'stopping' | 'restarting' | 'crashed',
|
|
603
|
-
pid: number | null,
|
|
604
|
-
uptime: number,
|
|
605
|
-
restartCount: number,
|
|
606
|
-
lastHealthCheck: object | null,
|
|
607
|
-
memoryUsage: object | null,
|
|
608
|
-
processManager: { type: 'direct' | 'pm2' }
|
|
609
|
-
}
|
|
610
|
-
```
|
|
611
|
-
|
|
612
|
-
**Events:**
|
|
613
|
-
- `state_change`
|
|
614
|
-
- `stdout`
|
|
615
|
-
- `stderr`
|
|
616
|
-
- `exit`
|
|
617
|
-
- `health_check`
|
|
618
|
-
- `unhealthy`
|
|
619
|
-
- `crashed`
|
|
620
|
-
|
|
621
|
-
### Remote_Process_Resource
|
|
622
|
-
|
|
623
|
-
Represents a remote HTTP-controlled process using the same lifecycle-oriented API style as `Process_Resource`.
|
|
624
|
-
|
|
625
|
-
**Extends:** `Resource`
|
|
626
|
-
|
|
627
|
-
**Constructor:**
|
|
628
|
-
```javascript
|
|
629
|
-
new Remote_Process_Resource(spec?: {
|
|
630
|
-
name?: string,
|
|
631
|
-
host: string,
|
|
632
|
-
port: number,
|
|
633
|
-
protocol?: 'http' | 'https',
|
|
634
|
-
pollIntervalMs?: number,
|
|
635
|
-
httpTimeoutMs?: number,
|
|
636
|
-
historySize?: number,
|
|
637
|
-
unreachableFailuresBeforeEvent?: number,
|
|
638
|
-
endpoints?: {
|
|
639
|
-
status?: string,
|
|
640
|
-
start?: string,
|
|
641
|
-
stop?: string,
|
|
642
|
-
health?: string
|
|
643
|
-
}
|
|
644
|
-
})
|
|
645
|
-
```
|
|
646
|
-
|
|
647
|
-
**Core Methods:**
|
|
648
|
-
- `start(callback?)`
|
|
649
|
-
- `stop(callback?)`
|
|
650
|
-
- `restart(callback?)`
|
|
651
|
-
- `get_abstract()`
|
|
652
|
-
|
|
653
|
-
**Status:** Includes `state`, `pid`, `uptime`, `restartCount`, `lastHealthCheck`, `memoryUsage`, and `processManager: { type: 'remote' }`.
|
|
654
|
-
|
|
655
|
-
**Events:**
|
|
656
|
-
- `state_change`
|
|
657
|
-
- `unreachable`
|
|
658
|
-
- `recovered`
|
|
659
|
-
|
|
660
|
-
### Server_Resource_Pool
|
|
661
|
-
|
|
662
|
-
Server-specific resource pool with lifecycle orchestration and event forwarding.
|
|
663
|
-
|
|
664
|
-
**Extends:** `Resource_Pool`
|
|
665
|
-
|
|
666
|
-
**Methods:**
|
|
667
|
-
- `add(resource)`
|
|
668
|
-
- `remove(name, callback?)`
|
|
669
|
-
- `start(callback?)`
|
|
670
|
-
- `stop(callback?)`
|
|
671
|
-
- `get_resources_by_type(type)`
|
|
672
|
-
|
|
673
|
-
**Properties:**
|
|
674
|
-
- `summary`: Aggregated state summary grouped by resource type.
|
|
675
|
-
|
|
676
|
-
**Forwarded Events:**
|
|
677
|
-
- `resource_state_change`
|
|
678
|
-
- `crashed`
|
|
679
|
-
- `unhealthy`
|
|
680
|
-
- `unreachable`
|
|
681
|
-
- `recovered`
|
|
682
|
-
|
|
683
|
-
### File_System_Resource
|
|
602
|
+
```javascript
|
|
603
|
+
serve(request: IncomingMessage, response: ServerResponse): Promise<void>
|
|
604
|
+
```
|
|
605
|
+
|
|
606
|
+
### HTTP_SSE_Publisher
|
|
607
|
+
|
|
608
|
+
General-purpose SSE publisher for explicit event fan-out.
|
|
609
|
+
|
|
610
|
+
**Extends:** `HTTP_Publisher`
|
|
611
|
+
|
|
612
|
+
**Constructor:**
|
|
613
|
+
```javascript
|
|
614
|
+
new HTTP_SSE_Publisher(spec?: {
|
|
615
|
+
name?: string,
|
|
616
|
+
keepaliveIntervalMs?: number,
|
|
617
|
+
maxClients?: number,
|
|
618
|
+
eventHistorySize?: number
|
|
619
|
+
})
|
|
620
|
+
```
|
|
621
|
+
|
|
622
|
+
**Methods:**
|
|
623
|
+
- `handle_http(req, res)`
|
|
624
|
+
- `broadcast(event_name, data_value)`
|
|
625
|
+
- `send(client_id, event_name, data_value)`
|
|
626
|
+
- `stop(callback?)`
|
|
627
|
+
|
|
628
|
+
**Properties:**
|
|
629
|
+
- `client_count` (number)
|
|
630
|
+
|
|
631
|
+
## Resource Classes
|
|
632
|
+
|
|
633
|
+
### Process_Resource
|
|
634
|
+
|
|
635
|
+
Represents a local process as a resource with a unified lifecycle API.
|
|
636
|
+
|
|
637
|
+
**Extends:** `Resource`
|
|
638
|
+
|
|
639
|
+
**Constructor:**
|
|
640
|
+
```javascript
|
|
641
|
+
new Process_Resource(spec?: {
|
|
642
|
+
name?: string,
|
|
643
|
+
command?: string,
|
|
644
|
+
args?: string[],
|
|
645
|
+
cwd?: string,
|
|
646
|
+
env?: object,
|
|
647
|
+
autoRestart?: boolean,
|
|
648
|
+
maxRestarts?: number,
|
|
649
|
+
processManager?: 'direct' | {
|
|
650
|
+
type: 'direct' | 'pm2',
|
|
651
|
+
pm2Path?: string,
|
|
652
|
+
ecosystem?: string
|
|
653
|
+
},
|
|
654
|
+
healthCheck?: {
|
|
655
|
+
type: 'http' | 'tcp' | 'custom',
|
|
656
|
+
url?: string,
|
|
657
|
+
host?: string,
|
|
658
|
+
port?: number,
|
|
659
|
+
fn?: Function,
|
|
660
|
+
intervalMs?: number,
|
|
661
|
+
timeoutMs?: number,
|
|
662
|
+
failuresBeforeUnhealthy?: number
|
|
663
|
+
}
|
|
664
|
+
})
|
|
665
|
+
```
|
|
666
|
+
|
|
667
|
+
**Core Methods:**
|
|
668
|
+
- `start(callback?)`
|
|
669
|
+
- `stop(callback?)`
|
|
670
|
+
- `restart(callback?)`
|
|
671
|
+
- `get_abstract()`
|
|
672
|
+
|
|
673
|
+
**Status:**
|
|
674
|
+
```javascript
|
|
675
|
+
{
|
|
676
|
+
state: 'stopped' | 'starting' | 'running' | 'stopping' | 'restarting' | 'crashed',
|
|
677
|
+
pid: number | null,
|
|
678
|
+
uptime: number,
|
|
679
|
+
restartCount: number,
|
|
680
|
+
lastHealthCheck: object | null,
|
|
681
|
+
memoryUsage: object | null,
|
|
682
|
+
processManager: { type: 'direct' | 'pm2' }
|
|
683
|
+
}
|
|
684
|
+
```
|
|
685
|
+
|
|
686
|
+
**Events:**
|
|
687
|
+
- `state_change`
|
|
688
|
+
- `stdout`
|
|
689
|
+
- `stderr`
|
|
690
|
+
- `exit`
|
|
691
|
+
- `health_check`
|
|
692
|
+
- `unhealthy`
|
|
693
|
+
- `crashed`
|
|
694
|
+
|
|
695
|
+
### Remote_Process_Resource
|
|
696
|
+
|
|
697
|
+
Represents a remote HTTP-controlled process using the same lifecycle-oriented API style as `Process_Resource`.
|
|
698
|
+
|
|
699
|
+
**Extends:** `Resource`
|
|
700
|
+
|
|
701
|
+
**Constructor:**
|
|
702
|
+
```javascript
|
|
703
|
+
new Remote_Process_Resource(spec?: {
|
|
704
|
+
name?: string,
|
|
705
|
+
host: string,
|
|
706
|
+
port: number,
|
|
707
|
+
protocol?: 'http' | 'https',
|
|
708
|
+
pollIntervalMs?: number,
|
|
709
|
+
httpTimeoutMs?: number,
|
|
710
|
+
historySize?: number,
|
|
711
|
+
unreachableFailuresBeforeEvent?: number,
|
|
712
|
+
endpoints?: {
|
|
713
|
+
status?: string,
|
|
714
|
+
start?: string,
|
|
715
|
+
stop?: string,
|
|
716
|
+
health?: string
|
|
717
|
+
}
|
|
718
|
+
})
|
|
719
|
+
```
|
|
720
|
+
|
|
721
|
+
**Core Methods:**
|
|
722
|
+
- `start(callback?)`
|
|
723
|
+
- `stop(callback?)`
|
|
724
|
+
- `restart(callback?)`
|
|
725
|
+
- `get_abstract()`
|
|
726
|
+
|
|
727
|
+
**Status:** Includes `state`, `pid`, `uptime`, `restartCount`, `lastHealthCheck`, `memoryUsage`, and `processManager: { type: 'remote' }`.
|
|
728
|
+
|
|
729
|
+
**Events:**
|
|
730
|
+
- `state_change`
|
|
731
|
+
- `unreachable`
|
|
732
|
+
- `recovered`
|
|
733
|
+
|
|
734
|
+
### Server_Resource_Pool
|
|
735
|
+
|
|
736
|
+
Server-specific resource pool with lifecycle orchestration and event forwarding.
|
|
737
|
+
|
|
738
|
+
**Extends:** `Resource_Pool`
|
|
739
|
+
|
|
740
|
+
**Methods:**
|
|
741
|
+
- `add(resource)`
|
|
742
|
+
- `remove(name, callback?)`
|
|
743
|
+
- `start(callback?)`
|
|
744
|
+
- `stop(callback?)`
|
|
745
|
+
- `get_resources_by_type(type)`
|
|
746
|
+
|
|
747
|
+
**Properties:**
|
|
748
|
+
- `summary`: Aggregated state summary grouped by resource type.
|
|
749
|
+
|
|
750
|
+
**Forwarded Events:**
|
|
751
|
+
- `resource_state_change`
|
|
752
|
+
- `crashed`
|
|
753
|
+
- `unhealthy`
|
|
754
|
+
- `unreachable`
|
|
755
|
+
- `recovered`
|
|
756
|
+
|
|
757
|
+
### File_System_Resource
|
|
684
758
|
|
|
685
759
|
Provides access to local file system.
|
|
686
760
|
|
|
@@ -912,10 +986,10 @@ ensure_route_leading_slash(route: string): string
|
|
|
912
986
|
### ServerOptions
|
|
913
987
|
|
|
914
988
|
```typescript
|
|
915
|
-
interface ServerOptions {
|
|
916
|
-
ctrl?: Function;
|
|
917
|
-
Ctrl?: Function;
|
|
918
|
-
src_path_client_js?: string;
|
|
989
|
+
interface ServerOptions {
|
|
990
|
+
ctrl?: Function;
|
|
991
|
+
Ctrl?: Function;
|
|
992
|
+
src_path_client_js?: string;
|
|
919
993
|
port?: number;
|
|
920
994
|
host?: string;
|
|
921
995
|
debug?: boolean;
|
|
@@ -928,60 +1002,66 @@ interface ServerOptions {
|
|
|
928
1002
|
api?: Record<string, Function>;
|
|
929
1003
|
static?: Record<string, string>;
|
|
930
1004
|
|
|
931
|
-
//
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
1005
|
+
// Middleware & compression
|
|
1006
|
+
middleware?: Function | Function[]; // (req, res, next) middleware functions
|
|
1007
|
+
compression?: boolean | { // Enable built-in compression middleware
|
|
1008
|
+
threshold?: number; // Min body size to compress (default 1024)
|
|
1009
|
+
level?: number; // zlib level (default Z_DEFAULT_COMPRESSION)
|
|
1010
|
+
};
|
|
1011
|
+
|
|
1012
|
+
// Advanced options
|
|
1013
|
+
cors?: CorsConfig;
|
|
1014
|
+
https?: HttpsConfig;
|
|
1015
|
+
publishers?: Record<string, Publisher>;
|
|
1016
|
+
resources?: ResourceEntries;
|
|
1017
|
+
events?: boolean | EventsOptions;
|
|
1018
|
+
bundler?: BundlerConfig;
|
|
1019
|
+
}
|
|
1020
|
+
```
|
|
1021
|
+
|
|
1022
|
+
```typescript
|
|
1023
|
+
type ResourceEntries = Record<string, ResourceEntry> | ResourceEntry[];
|
|
1024
|
+
|
|
1025
|
+
type ResourceEntry =
|
|
1026
|
+
| Resource
|
|
1027
|
+
| {
|
|
1028
|
+
type?: 'process' | 'local';
|
|
1029
|
+
command?: string;
|
|
1030
|
+
args?: string[];
|
|
1031
|
+
processManager?: 'direct' | {
|
|
1032
|
+
type?: 'direct' | 'pm2';
|
|
1033
|
+
pm2Path?: string;
|
|
1034
|
+
ecosystem?: string;
|
|
1035
|
+
};
|
|
1036
|
+
[key: string]: any;
|
|
1037
|
+
}
|
|
1038
|
+
| {
|
|
1039
|
+
type?: 'remote' | 'http';
|
|
1040
|
+
host?: string;
|
|
1041
|
+
port?: number;
|
|
1042
|
+
protocol?: 'http' | 'https';
|
|
1043
|
+
endpoints?: Record<string, string>;
|
|
1044
|
+
[key: string]: any;
|
|
1045
|
+
}
|
|
1046
|
+
| {
|
|
1047
|
+
type?: 'resource' | 'in_process' | 'in-process';
|
|
1048
|
+
instance?: Resource;
|
|
1049
|
+
resource?: Resource;
|
|
1050
|
+
class?: new (spec?: any) => Resource;
|
|
1051
|
+
Ctor?: new (spec?: any) => Resource;
|
|
1052
|
+
constructor_fn?: new (spec?: any) => Resource;
|
|
1053
|
+
spec?: Record<string, any>;
|
|
1054
|
+
[key: string]: any;
|
|
1055
|
+
};
|
|
1056
|
+
|
|
1057
|
+
interface EventsOptions {
|
|
1058
|
+
route?: string;
|
|
1059
|
+
name?: string;
|
|
1060
|
+
keepaliveIntervalMs?: number;
|
|
1061
|
+
maxClients?: number;
|
|
1062
|
+
eventHistorySize?: number;
|
|
1063
|
+
}
|
|
1064
|
+
```
|
|
985
1065
|
|
|
986
1066
|
### PageConfig
|
|
987
1067
|
|
|
@@ -1287,4 +1367,4 @@ const server = await Server.serve({
|
|
|
1287
1367
|
|
|
1288
1368
|
---
|
|
1289
1369
|
|
|
1290
|
-
This API reference provides comprehensive technical documentation for JSGUI3 Server internals. For practical usage examples and tutorials, refer to the user-facing documentation.
|
|
1370
|
+
This API reference provides comprehensive technical documentation for JSGUI3 Server internals. For practical usage examples and tutorials, refer to the user-facing documentation.
|