@3sixty/api-server-native 0.20.0-next.0 → 0.20.0-next.1

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.
@@ -0,0 +1,834 @@
1
+ # Class: NativeWebServer
2
+
3
+ Implementation of the web server using the Node.js HTTP server and the find-my-way router.
4
+
5
+ ## Extends
6
+
7
+ - `BaseServer`\<`Router.Instance`\<`Router.HTTPVersion.V1`\>\>
8
+
9
+ ## Constructors
10
+
11
+ ### Constructor
12
+
13
+ > **new NativeWebServer**(`options?`): `NativeWebServer`
14
+
15
+ Create a new instance of NativeWebServer.
16
+
17
+ #### Parameters
18
+
19
+ ##### options?
20
+
21
+ [`INativeWebServerConstructorOptions`](../interfaces/INativeWebServerConstructorOptions.md)
22
+
23
+ The options for the server.
24
+
25
+ #### Returns
26
+
27
+ `NativeWebServer`
28
+
29
+ #### Overrides
30
+
31
+ `BaseServer<Router.Instance<Router.HTTPVersion.V1>>.constructor`
32
+
33
+ ## Properties
34
+
35
+ ### \_loggingComponentType? {#_loggingcomponenttype}
36
+
37
+ > `protected` `readonly` `optional` **\_loggingComponentType?**: `string`
38
+
39
+ The logging component type.
40
+
41
+ #### Inherited from
42
+
43
+ `BaseServer._loggingComponentType`
44
+
45
+ ***
46
+
47
+ ### \_logging? {#_logging}
48
+
49
+ > `protected` `readonly` `optional` **\_logging?**: `ILoggingComponent`
50
+
51
+ The logging component.
52
+
53
+ #### Inherited from
54
+
55
+ `BaseServer._logging`
56
+
57
+ ***
58
+
59
+ ### \_options? {#_options}
60
+
61
+ > `protected` `optional` **\_options?**: `IWebServerOptions`
62
+
63
+ The options for the server.
64
+
65
+ #### Inherited from
66
+
67
+ `BaseServer._options`
68
+
69
+ ***
70
+
71
+ ### \_started {#_started}
72
+
73
+ > `protected` **\_started**: `boolean`
74
+
75
+ Whether the server has been started.
76
+
77
+ #### Inherited from
78
+
79
+ `BaseServer._started`
80
+
81
+ ***
82
+
83
+ ### \_mimeTypeProcessors {#_mimetypeprocessors}
84
+
85
+ > `protected` `readonly` **\_mimeTypeProcessors**: `IMimeTypeProcessor`[]
86
+
87
+ The mime type processors.
88
+
89
+ #### Inherited from
90
+
91
+ `BaseServer._mimeTypeProcessors`
92
+
93
+ ***
94
+
95
+ ### \_includeErrorStack {#_includeerrorstack}
96
+
97
+ > `protected` `readonly` **\_includeErrorStack**: `boolean`
98
+
99
+ Include the stack with errors.
100
+
101
+ #### Inherited from
102
+
103
+ `BaseServer._includeErrorStack`
104
+
105
+ ***
106
+
107
+ ### \_publicOrigin? {#_publicorigin}
108
+
109
+ > `protected` `optional` **\_publicOrigin?**: `string`
110
+
111
+ The public origin of the server, used for constructing the request URL and for CORS.
112
+
113
+ #### Inherited from
114
+
115
+ `BaseServer._publicOrigin`
116
+
117
+ ***
118
+
119
+ ### \_localOrigin? {#_localorigin}
120
+
121
+ > `protected` `optional` **\_localOrigin?**: `string`
122
+
123
+ The local origin of the server, used for constructing the request URL and for CORS.
124
+
125
+ #### Inherited from
126
+
127
+ `BaseServer._localOrigin`
128
+
129
+ ***
130
+
131
+ ### \_restChains {#_restchains}
132
+
133
+ > `protected` **\_restChains**: `IRestProcessorChains`
134
+
135
+ The REST processor chains resolved when the server is built.
136
+
137
+ #### Inherited from
138
+
139
+ `BaseServer._restChains`
140
+
141
+ ***
142
+
143
+ ### \_socketChains {#_socketchains}
144
+
145
+ > `protected` **\_socketChains**: `ISocketProcessorChains`
146
+
147
+ The socket processor chains resolved when the server is built.
148
+
149
+ #### Inherited from
150
+
151
+ `BaseServer._socketChains`
152
+
153
+ ***
154
+
155
+ ### CLASS\_NAME {#class_name}
156
+
157
+ > `readonly` `static` **CLASS\_NAME**: `string`
158
+
159
+ Runtime name for the class.
160
+
161
+ #### Overrides
162
+
163
+ `BaseServer.CLASS_NAME`
164
+
165
+ ## Methods
166
+
167
+ ### start() {#start}
168
+
169
+ > **start**(): `Promise`\<`void`\>
170
+
171
+ Start the server.
172
+
173
+ #### Returns
174
+
175
+ `Promise`\<`void`\>
176
+
177
+ A promise that resolves when the server is listening for connections.
178
+
179
+ #### Inherited from
180
+
181
+ `BaseServer.start`
182
+
183
+ ***
184
+
185
+ ### stop() {#stop}
186
+
187
+ > **stop**(): `Promise`\<`void`\>
188
+
189
+ Stop the server.
190
+
191
+ #### Returns
192
+
193
+ `Promise`\<`void`\>
194
+
195
+ A promise that resolves when the server has shut down all connections.
196
+
197
+ #### Inherited from
198
+
199
+ `BaseServer.stop`
200
+
201
+ ***
202
+
203
+ ### health() {#health}
204
+
205
+ > **health**(): `Promise`\<`IHealth`[]\>
206
+
207
+ Returns the health status of the component.
208
+
209
+ #### Returns
210
+
211
+ `Promise`\<`IHealth`[]\>
212
+
213
+ The health status of the component, can return multiple entries for elements within the component.
214
+
215
+ #### Inherited from
216
+
217
+ `BaseServer.health`
218
+
219
+ ***
220
+
221
+ ### healthApplication() {#healthapplication}
222
+
223
+ > **healthApplication**(`callback`): `Promise`\<`IHealth`[] \| `undefined`\>
224
+
225
+ Verify the root endpoint is reachable and returns a body by making a real HTTP request.
226
+ Skipped when GET / is not registered on this server instance.
227
+
228
+ #### Parameters
229
+
230
+ ##### callback
231
+
232
+ `HealthApplicationCallback`
233
+
234
+ The callback to invoke when a deferred health result is ready.
235
+
236
+ #### Returns
237
+
238
+ `Promise`\<`IHealth`[] \| `undefined`\>
239
+
240
+ The application health status of the component.
241
+
242
+ #### Inherited from
243
+
244
+ `BaseServer.healthApplication`
245
+
246
+ ***
247
+
248
+ ### requestLocalRoot() {#requestlocalroot}
249
+
250
+ > `protected` **requestLocalRoot**(`url`): `Promise`\<\{ `ok`: `boolean`; `body`: `string`; \}\>
251
+
252
+ Request the root endpoint of this server over the loopback address.
253
+
254
+ #### Parameters
255
+
256
+ ##### url
257
+
258
+ `string`
259
+
260
+ The url of the root endpoint.
261
+
262
+ #### Returns
263
+
264
+ `Promise`\<\{ `ok`: `boolean`; `body`: `string`; \}\>
265
+
266
+ Whether the response was successful and its body.
267
+
268
+ #### Inherited from
269
+
270
+ `BaseServer.requestLocalRoot`
271
+
272
+ ***
273
+
274
+ ### prepareBuild() {#preparebuild}
275
+
276
+ > `protected` **prepareBuild**(`restRouteProcessors?`, `restRoutes?`, `socketRouteProcessors?`, `socketRoutes?`, `options?`): `Promise`\<`void`\>
277
+
278
+ Perform the transport agnostic part of building the server, validating the routes and
279
+ processors, resolving the origins and resolving the processor chains.
280
+
281
+ #### Parameters
282
+
283
+ ##### restRouteProcessors?
284
+
285
+ `IRestRouteProcessor`[]
286
+
287
+ The processors for incoming requests over REST.
288
+
289
+ ##### restRoutes?
290
+
291
+ `IRestRoute`\<`any`, `any`\>[]
292
+
293
+ The REST routes.
294
+
295
+ ##### socketRouteProcessors?
296
+
297
+ `ISocketRouteProcessor`[]
298
+
299
+ The processors for incoming requests over Sockets.
300
+
301
+ ##### socketRoutes?
302
+
303
+ `ISocketRoute`\<`any`, `any`\>[]
304
+
305
+ The socket routes.
306
+
307
+ ##### options?
308
+
309
+ `IWebServerOptions`
310
+
311
+ Options for building the server.
312
+
313
+ #### Returns
314
+
315
+ `Promise`\<`void`\>
316
+
317
+ A promise that resolves when the shared build steps are complete.
318
+
319
+ #### Inherited from
320
+
321
+ `BaseServer.prepareBuild`
322
+
323
+ ***
324
+
325
+ ### buildProcessorChains() {#buildprocessorchains}
326
+
327
+ > `protected` **buildProcessorChains**(`restRouteProcessors?`, `socketRouteProcessors?`): `void`
328
+
329
+ Resolve the route processors in to per phase chains, so that the lookups and bindings
330
+ are performed once when the server is built instead of on every request.
331
+
332
+ #### Parameters
333
+
334
+ ##### restRouteProcessors?
335
+
336
+ `IRestRouteProcessor`[]
337
+
338
+ The processors for the incoming REST requests.
339
+
340
+ ##### socketRouteProcessors?
341
+
342
+ `ISocketRouteProcessor`[]
343
+
344
+ The processors for the incoming socket requests.
345
+
346
+ #### Returns
347
+
348
+ `void`
349
+
350
+ #### Inherited from
351
+
352
+ `BaseServer.buildProcessorChains`
353
+
354
+ ***
355
+
356
+ ### resolveBodyLimits() {#resolvebodylimits}
357
+
358
+ > `protected` **resolveBodyLimits**(): `object`
359
+
360
+ Merge the configured body limits over the built-in ones and validate them.
361
+
362
+ #### Returns
363
+
364
+ `object`
365
+
366
+ The named body limits in bytes.
367
+
368
+ #### Throws
369
+
370
+ GeneralError If a limit is not a positive integer.
371
+
372
+ #### Inherited from
373
+
374
+ `BaseServer.resolveBodyLimits`
375
+
376
+ ***
377
+
378
+ ### resolveCorsOptions() {#resolvecorsoptions}
379
+
380
+ > `protected` **resolveCorsOptions**(`options?`): `IServerCorsOptions`
381
+
382
+ Resolve the CORS options from the web server options, merging in the defaults.
383
+
384
+ #### Parameters
385
+
386
+ ##### options?
387
+
388
+ `IWebServerOptions`
389
+
390
+ The web server options.
391
+
392
+ #### Returns
393
+
394
+ `IServerCorsOptions`
395
+
396
+ The resolved CORS options.
397
+
398
+ #### Inherited from
399
+
400
+ `BaseServer.resolveCorsOptions`
401
+
402
+ ***
403
+
404
+ ### buildServerRequest() {#buildserverrequest}
405
+
406
+ > `protected` **buildServerRequest**(`method`, `url`, `body`, `query?`, `pathParams?`, `headers?`): `IHttpServerRequest`
407
+
408
+ Build the server request from the transport values, the path params and query must already
409
+ have been decoded by the transport, as decoding them again corrupts values containing %.
410
+
411
+ #### Parameters
412
+
413
+ ##### method
414
+
415
+ `HttpMethod`
416
+
417
+ The request method.
418
+
419
+ ##### url
420
+
421
+ `string`
422
+
423
+ The full request url, including the origin.
424
+
425
+ ##### body
426
+
427
+ `unknown`
428
+
429
+ The request body.
430
+
431
+ ##### query?
432
+
433
+ `IHttpRequestQuery`
434
+
435
+ The request query params.
436
+
437
+ ##### pathParams?
438
+
439
+ `IHttpRequestPathParams`
440
+
441
+ The request path params.
442
+
443
+ ##### headers?
444
+
445
+ `IHttpHeaders`
446
+
447
+ The request headers.
448
+
449
+ #### Returns
450
+
451
+ `IHttpServerRequest`
452
+
453
+ The server request.
454
+
455
+ #### Inherited from
456
+
457
+ `BaseServer.buildServerRequest`
458
+
459
+ ***
460
+
461
+ ### validateResponse() {#validateresponse}
462
+
463
+ > `protected` **validateResponse**(`httpResponse`): `void`
464
+
465
+ Validate the processed response before it is sent, so that every transport fails an invalid
466
+ response in the same way rather than with its own transport specific error.
467
+
468
+ #### Parameters
469
+
470
+ ##### httpResponse
471
+
472
+ `IHttpResponse`
473
+
474
+ The processed response.
475
+
476
+ #### Returns
477
+
478
+ `void`
479
+
480
+ #### Throws
481
+
482
+ GeneralError If the status code or a header is invalid.
483
+
484
+ #### Inherited from
485
+
486
+ `BaseServer.validateResponse`
487
+
488
+ ***
489
+
490
+ ### buildContextIds() {#buildcontextids}
491
+
492
+ > `protected` **buildContextIds**(`requestOrigin`, `headers?`): `IContextIds`
493
+
494
+ Build the context ids for an incoming request.
495
+
496
+ #### Parameters
497
+
498
+ ##### requestOrigin
499
+
500
+ `string`
501
+
502
+ The origin the request was received on.
503
+
504
+ ##### headers?
505
+
506
+ `IHttpHeaders`
507
+
508
+ The request headers.
509
+
510
+ #### Returns
511
+
512
+ `IContextIds`
513
+
514
+ The context ids.
515
+
516
+ #### Inherited from
517
+
518
+ `BaseServer.buildContextIds`
519
+
520
+ ***
521
+
522
+ ### runProcessorsRest() {#runprocessorsrest}
523
+
524
+ > `protected` **runProcessorsRest**(`restRoute`, `httpServerRequest`, `httpResponse`, `contextIds`, `processorState`): `Promise`\<`void`\>
525
+
526
+ Run the REST processors for the route.
527
+
528
+ #### Parameters
529
+
530
+ ##### restRoute
531
+
532
+ `IRestRoute`\<`any`, `any`\> \| `undefined`
533
+
534
+ The route to process.
535
+
536
+ ##### httpServerRequest
537
+
538
+ `IHttpServerRequest`
539
+
540
+ The incoming request.
541
+
542
+ ##### httpResponse
543
+
544
+ `IHttpResponse`
545
+
546
+ The outgoing response.
547
+
548
+ ##### contextIds
549
+
550
+ `IContextIds`
551
+
552
+ The context IDs of the request.
553
+
554
+ ##### processorState
555
+
556
+ \{\[`id`: `string`\]: `unknown`; \}
557
+
558
+ The state handed through the processors.
559
+
560
+ #### Returns
561
+
562
+ `Promise`\<`void`\>
563
+
564
+ #### Inherited from
565
+
566
+ `BaseServer.runProcessorsRest`
567
+
568
+ ***
569
+
570
+ ### runProcessorsSocket() {#runprocessorssocket}
571
+
572
+ > `protected` **runProcessorsSocket**(`socketRoute`, `socketServerRequest`, `httpResponse`, `contextIds`, `processorState`, `requestTopic`, `responseEmitter`): `Promise`\<`void`\>
573
+
574
+ Run the socket processors for the route.
575
+
576
+ #### Parameters
577
+
578
+ ##### socketRoute
579
+
580
+ `ISocketRoute`
581
+
582
+ The route to process.
583
+
584
+ ##### socketServerRequest
585
+
586
+ `ISocketServerRequest`
587
+
588
+ The incoming request.
589
+
590
+ ##### httpResponse
591
+
592
+ `IHttpResponse`
593
+
594
+ The outgoing response.
595
+
596
+ ##### contextIds
597
+
598
+ `IContextIds`
599
+
600
+ The context IDs of the request.
601
+
602
+ ##### processorState
603
+
604
+ \{\[`id`: `string`\]: `unknown`; \}
605
+
606
+ The state handed through the processors.
607
+
608
+ ##### requestTopic
609
+
610
+ `string`
611
+
612
+ The topic of the request.
613
+
614
+ ##### responseEmitter
615
+
616
+ (`topic`, `response`) => `Promise`\<`void`\>
617
+
618
+ The emitter to send the response on.
619
+
620
+ #### Returns
621
+
622
+ `Promise`\<`void`\>
623
+
624
+ #### Inherited from
625
+
626
+ `BaseServer.runProcessorsSocket`
627
+
628
+ ***
629
+
630
+ ### className() {#classname}
631
+
632
+ > **className**(): `string`
633
+
634
+ Returns the class name of the component.
635
+
636
+ #### Returns
637
+
638
+ `string`
639
+
640
+ The class name of the component.
641
+
642
+ #### Overrides
643
+
644
+ `BaseServer.className`
645
+
646
+ ***
647
+
648
+ ### getInstance() {#getinstance}
649
+
650
+ > **getInstance**(): `Instance`\<`V1`\>
651
+
652
+ Get the web server instance.
653
+
654
+ #### Returns
655
+
656
+ `Instance`\<`V1`\>
657
+
658
+ The web server instance.
659
+
660
+ #### Overrides
661
+
662
+ `BaseServer.getInstance`
663
+
664
+ ***
665
+
666
+ ### build() {#build}
667
+
668
+ > **build**(`restRouteProcessors?`, `restRoutes?`, `socketRouteProcessors?`, `socketRoutes?`, `options?`): `Promise`\<`void`\>
669
+
670
+ Build the server.
671
+
672
+ #### Parameters
673
+
674
+ ##### restRouteProcessors?
675
+
676
+ `IRestRouteProcessor`[]
677
+
678
+ The processors for incoming requests over REST.
679
+
680
+ ##### restRoutes?
681
+
682
+ `IRestRoute`\<`any`, `any`\>[]
683
+
684
+ The REST routes.
685
+
686
+ ##### socketRouteProcessors?
687
+
688
+ `ISocketRouteProcessor`[]
689
+
690
+ The processors for incoming requests over Sockets.
691
+
692
+ ##### socketRoutes?
693
+
694
+ `ISocketRoute`\<`any`, `any`\>[]
695
+
696
+ The socket routes.
697
+
698
+ ##### options?
699
+
700
+ `IWebServerOptions`
701
+
702
+ Options for building the server.
703
+
704
+ #### Returns
705
+
706
+ `Promise`\<`void`\>
707
+
708
+ A promise that resolves when the server is fully built and ready to start.
709
+
710
+ #### Overrides
711
+
712
+ `BaseServer.build`
713
+
714
+ ***
715
+
716
+ ### serverListen() {#serverlisten}
717
+
718
+ > `protected` **serverListen**(`host`, `port`): `Promise`\<`void`\>
719
+
720
+ Start listening for connections on the transport.
721
+
722
+ #### Parameters
723
+
724
+ ##### host
725
+
726
+ `string`
727
+
728
+ The host to bind to.
729
+
730
+ ##### port
731
+
732
+ `number`
733
+
734
+ The port to bind to.
735
+
736
+ #### Returns
737
+
738
+ `Promise`\<`void`\>
739
+
740
+ A promise that resolves when the transport is listening.
741
+
742
+ #### Overrides
743
+
744
+ `BaseServer.serverListen`
745
+
746
+ ***
747
+
748
+ ### serverClose() {#serverclose}
749
+
750
+ > `protected` **serverClose**(): `Promise`\<`void`\>
751
+
752
+ Close the transport and all of its connections.
753
+
754
+ #### Returns
755
+
756
+ `Promise`\<`void`\>
757
+
758
+ A promise that resolves when the transport has closed.
759
+
760
+ #### Overrides
761
+
762
+ `BaseServer.serverClose`
763
+
764
+ ***
765
+
766
+ ### serverAddresses() {#serveraddresses}
767
+
768
+ > `protected` **serverAddresses**(): `object`[]
769
+
770
+ Get the addresses the transport is bound to.
771
+
772
+ #### Returns
773
+
774
+ `object`[]
775
+
776
+ The bound addresses.
777
+
778
+ #### Overrides
779
+
780
+ `BaseServer.serverAddresses`
781
+
782
+ ***
783
+
784
+ ### serverIsSecure() {#serverissecure}
785
+
786
+ > `protected` **serverIsSecure**(): `boolean`
787
+
788
+ Whether the transport is serving over TLS.
789
+
790
+ #### Returns
791
+
792
+ `boolean`
793
+
794
+ True if the transport is secure.
795
+
796
+ #### Overrides
797
+
798
+ `BaseServer.serverIsSecure`
799
+
800
+ ***
801
+
802
+ ### serverIsListening() {#serverislistening}
803
+
804
+ > `protected` **serverIsListening**(): `boolean`
805
+
806
+ Whether the transport is currently listening for connections.
807
+
808
+ #### Returns
809
+
810
+ `boolean`
811
+
812
+ True if the transport is listening.
813
+
814
+ #### Overrides
815
+
816
+ `BaseServer.serverIsListening`
817
+
818
+ ***
819
+
820
+ ### serverHasRootRoute() {#serverhasrootroute}
821
+
822
+ > `protected` **serverHasRootRoute**(): `boolean`
823
+
824
+ Whether a GET route is registered for the root path.
825
+
826
+ #### Returns
827
+
828
+ `boolean`
829
+
830
+ True if the root route is registered.
831
+
832
+ #### Overrides
833
+
834
+ `BaseServer.serverHasRootRoute`