@nsshunt/stsappframework 3.0.103 → 3.0.105
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/dist/authutilsnode.js +6 -7
- package/dist/authutilsnode.js.map +1 -1
- package/dist/influxdb/influxDBManager.js +16 -17
- package/dist/influxdb/influxDBManager.js.map +1 -1
- package/dist/influxdb/influxDBManagerAgent.js +9 -13
- package/dist/influxdb/influxDBManagerAgent.js.map +1 -1
- package/dist/influxdb/influxDBManagerBase.js +2 -6
- package/dist/influxdb/influxDBManagerBase.js.map +1 -1
- package/dist/influxdb/influxDBManagerService.js +10 -14
- package/dist/influxdb/influxDBManagerService.js.map +1 -1
- package/dist/instrumentationsubscriber.js +11 -15
- package/dist/instrumentationsubscriber.js.map +1 -1
- package/dist/kafka/IMKafkaManager.js +2 -6
- package/dist/kafka/IMKafkaManager.js.map +1 -1
- package/dist/kafkatesting/produce.js +1 -5
- package/dist/kafkatesting/produce.js.map +1 -1
- package/dist/masterprocessbase.js +19 -20
- package/dist/masterprocessbase.js.map +1 -1
- package/dist/processbase.js +8 -10
- package/dist/processbase.js.map +1 -1
- package/dist/server.js +1 -1
- package/dist/server.js.map +1 -1
- package/dist/singleprocessbase.js +3 -4
- package/dist/singleprocessbase.js.map +1 -1
- package/dist/tcpclient/app2.js +2 -2
- package/dist/tcpserver/appmaster.js +39 -16
- package/dist/tcpserver/appmaster.js.map +1 -1
- package/dist/workerprocessbase.js +3 -4
- package/dist/workerprocessbase.js.map +1 -1
- package/package.json +7 -7
- package/src/authutilsnode.ts +8 -10
- package/src/influxdb/influxDBManager.ts +16 -18
- package/src/influxdb/influxDBManagerAgent.ts +9 -11
- package/src/influxdb/influxDBManagerBase.ts +2 -4
- package/src/influxdb/influxDBManagerService.ts +10 -12
- package/src/instrumentationsubscriber.ts +11 -14
- package/src/kafka/IMKafkaManager.ts +2 -4
- package/src/kafkatesting/produce.ts +1 -3
- package/src/masterprocessbase.ts +32 -24
- package/src/processbase.ts +7 -11
- package/src/server.ts +1 -1
- package/src/singleprocessbase.ts +3 -5
- package/src/tcpclient/app2.ts +2 -2
- package/src/tcpserver/appmaster.ts +39 -17
- package/src/workerprocessbase.ts +3 -5
- package/types/authutilsnode.d.ts.map +1 -1
- package/types/influxdb/influxDBManager.d.ts.map +1 -1
- package/types/influxdb/influxDBManagerAgent.d.ts.map +1 -1
- package/types/influxdb/influxDBManagerBase.d.ts.map +1 -1
- package/types/influxdb/influxDBManagerService.d.ts.map +1 -1
- package/types/instrumentationsubscriber.d.ts.map +1 -1
- package/types/kafka/IMKafkaManager.d.ts.map +1 -1
- package/types/masterprocessbase.d.ts.map +1 -1
- package/types/processbase.d.ts +2 -2
- package/types/processbase.d.ts.map +1 -1
- package/types/singleprocessbase.d.ts.map +1 -1
- package/types/tcpserver/appmaster.d.ts.map +1 -1
- package/types/workerprocessbase.d.ts.map +1 -1
- package/src_new/authDefs.ts +0 -37
- package/src_new/authutilsnode.ts +0 -375
- package/src_new/commonTypes.ts +0 -239
- package/src_new/index.ts +0 -22
- package/src_new/influxdb/influxDBManager.ts +0 -972
- package/src_new/influxdb/influxDBManagerAgent.ts +0 -316
- package/src_new/influxdb/influxDBManagerBase.ts +0 -111
- package/src_new/influxdb/influxDBManagerService.ts +0 -375
- package/src_new/instrumentationsubscriber.ts +0 -286
- package/src_new/kafka/IMKafkaManager.ts +0 -154
- package/src_new/kafka/kafkaconsumer.ts +0 -82
- package/src_new/kafka/kafkamanager.ts +0 -186
- package/src_new/kafka/kafkaproducer.ts +0 -58
- package/src_new/kafkatesting/config.ts +0 -10
- package/src_new/kafkatesting/consume.ts +0 -116
- package/src_new/kafkatesting/produce.ts +0 -155
- package/src_new/masterprocessbase.ts +0 -590
- package/src_new/middleware/serverNetworkMiddleware.ts +0 -240
- package/src_new/network.ts +0 -36
- package/src_new/processbase.ts +0 -413
- package/src_new/processoptions.ts +0 -164
- package/src_new/publishertransports/publishTransportDirect.ts +0 -45
- package/src_new/publishertransports/publishTransportUtils.ts +0 -53
- package/src_new/server.ts +0 -141
- package/src_new/serverprocessbase.ts +0 -393
- package/src_new/singleprocessbase.ts +0 -123
- package/src_new/socketIoServerHelper.ts +0 -177
- package/src_new/stscontrollerbase.ts +0 -15
- package/src_new/stslatencycontroller.ts +0 -27
- package/src_new/stslatencyroute.ts +0 -16
- package/src_new/stsrouterbase.ts +0 -22
- package/src_new/tcpclient/app.ts +0 -19
- package/src_new/tcpclient/app2.ts +0 -56
- package/src_new/tcpserver/app.ts +0 -11
- package/src_new/tcpserver/appConfig.ts +0 -65
- package/src_new/tcpserver/appmaster.ts +0 -522
- package/src_new/validation/errors.ts +0 -6
- package/src_new/webworkertesting/app.ts +0 -49
- package/src_new/webworkertesting/worker.ts +0 -24
- package/src_new/workerprocessbase.test.ts +0 -47
- package/src_new/workerprocessbase.ts +0 -187
- package/src_working/authDefs.ts +0 -37
- package/src_working/authutilsnode.ts +0 -373
- package/src_working/commonTypes.ts +0 -239
- package/src_working/index.ts +0 -22
- package/src_working/influxdb/influxDBManager.ts +0 -970
- package/src_working/influxdb/influxDBManagerAgent.ts +0 -314
- package/src_working/influxdb/influxDBManagerBase.ts +0 -109
- package/src_working/influxdb/influxDBManagerService.ts +0 -373
- package/src_working/instrumentationsubscriber.ts +0 -283
- package/src_working/kafka/IMKafkaManager.ts +0 -152
- package/src_working/kafka/kafkaconsumer.ts +0 -82
- package/src_working/kafka/kafkamanager.ts +0 -186
- package/src_working/kafka/kafkaproducer.ts +0 -58
- package/src_working/kafkatesting/config.ts +0 -10
- package/src_working/kafkatesting/consume.ts +0 -116
- package/src_working/kafkatesting/produce.ts +0 -153
- package/src_working/masterprocessbase.ts +0 -598
- package/src_working/middleware/serverNetworkMiddleware.ts +0 -240
- package/src_working/network.ts +0 -36
- package/src_working/processbase.ts +0 -411
- package/src_working/processoptions.ts +0 -164
- package/src_working/publishertransports/publishTransportDirect.ts +0 -45
- package/src_working/publishertransports/publishTransportUtils.ts +0 -53
- package/src_working/server.ts +0 -141
- package/src_working/serverprocessbase.ts +0 -393
- package/src_working/singleprocessbase.ts +0 -121
- package/src_working/socketIoServerHelper.ts +0 -177
- package/src_working/stscontrollerbase.ts +0 -15
- package/src_working/stslatencycontroller.ts +0 -27
- package/src_working/stslatencyroute.ts +0 -16
- package/src_working/stsrouterbase.ts +0 -22
- package/src_working/tcpclient/app.ts +0 -19
- package/src_working/tcpclient/app2.ts +0 -56
- package/src_working/tcpserver/app.ts +0 -11
- package/src_working/tcpserver/appConfig.ts +0 -65
- package/src_working/tcpserver/appmaster.ts +0 -544
- package/src_working/validation/errors.ts +0 -6
- package/src_working/webworkertesting/app.ts +0 -49
- package/src_working/webworkertesting/worker.ts +0 -24
- package/src_working/workerprocessbase.test.ts +0 -47
- package/src_working/workerprocessbase.ts +0 -185
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import { IServiceProcessContext } from '@nsshunt/stspublisherserver'
|
|
2
|
-
//import { JSONObject } from '@nsshunt/stsutils'
|
|
3
|
-
import express from 'express'
|
|
4
|
-
|
|
5
|
-
import { IProcessBase } from './commonTypes'
|
|
6
|
-
|
|
7
|
-
export interface STSExpressServer {
|
|
8
|
-
get App(): express.Express
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Factory method that adds express routes to the express app object.
|
|
13
|
-
*/
|
|
14
|
-
export type ExpressRouteFactory = (app: express.Express, stsApp: IProcessBase) => void
|
|
15
|
-
|
|
16
|
-
export enum STSServerType {
|
|
17
|
-
NONE = "NONE",
|
|
18
|
-
EXPRESS = "EXPRESS",
|
|
19
|
-
EXPRESS_TLS = "EXPRESS_TLS",
|
|
20
|
-
TCPRAW_TLS = "TCPRAW_TLS",
|
|
21
|
-
JSONRPC2_TLS = "JSONRPC_TLS"
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
//export interface ProcessOptions extends JSONObject {
|
|
25
|
-
export interface ProcessOptions {
|
|
26
|
-
/**
|
|
27
|
-
* Is this service worker the master worker (thread).
|
|
28
|
-
*/
|
|
29
|
-
isMaster: boolean
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Unique service instance ID (uuidv4).
|
|
33
|
-
*/
|
|
34
|
-
serviceInstanceId: string
|
|
35
|
-
|
|
36
|
-
// Service details
|
|
37
|
-
|
|
38
|
-
serverType: STSServerType
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* HTTPS service public key path.
|
|
42
|
-
*/
|
|
43
|
-
httpsServerKeyPath: string
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* HTTPS service certificate (private key) path.
|
|
47
|
-
*/
|
|
48
|
-
httpsServerCertificatePath: string
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Determines whether the process will explicitly exit (using code 0) when any terminate signal is received.
|
|
52
|
-
*/
|
|
53
|
-
processExitOnTerminate: boolean
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Does this service run a Web Socket Server (wss).
|
|
57
|
-
*/
|
|
58
|
-
wssServer: boolean
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Service Prometheus metric support.
|
|
62
|
-
*/
|
|
63
|
-
prometheusSupport: boolean
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Service endpoint (without trailing /). Example: https://localhost
|
|
67
|
-
*/
|
|
68
|
-
endpoint: string
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Service API root (without trailing /). Example: /stsrest01/v1
|
|
72
|
-
*/
|
|
73
|
-
apiRoot: string
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Service listen port. Example: 3001.
|
|
77
|
-
* Note that unix domain sockets are also supported. Example: /tmp/stsrest01.sock.
|
|
78
|
-
* The socket file may also need permissions changed, i.e. chmodSync(port, 511); or chmodSync(port, 777);
|
|
79
|
-
* Axios client calls will also need to use socketPath. Example: ..., socketPath: '/tmp/stsrest01.sock'
|
|
80
|
-
* Ref: https://stackoverflow.com/questions/21342828/node-express-unix-domain-socket-permissions
|
|
81
|
-
* To setup side car service (per running machine/node)
|
|
82
|
-
* sudo mkdir /var/run/sts
|
|
83
|
-
* sudo chown marcusbettens /var/run/sts
|
|
84
|
-
* In .env file per service
|
|
85
|
-
* PORT=/var/run/sts/stsrest01.sock
|
|
86
|
-
*/
|
|
87
|
-
listenPort: string
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Port that this service will be exposed externally on, i.e. clients will use this port to invoke APIs on this service.
|
|
91
|
-
*/
|
|
92
|
-
port: string
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Prometheus Cluster Server port (port used for cluster prometheus scrapes). Example: 3011.
|
|
96
|
-
*/
|
|
97
|
-
prometheusClusterPort: string
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Service Name. Example: Rest01
|
|
101
|
-
*/
|
|
102
|
-
serviceName: string
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Service Version. Example: 1.0.0
|
|
106
|
-
*/
|
|
107
|
-
serviceVersion: string
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Determines where logging is output to the console (stdout).
|
|
111
|
-
*/
|
|
112
|
-
consoleLogging: boolean
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Determines where logging is output to the logging instrument (if present).
|
|
116
|
-
*/
|
|
117
|
-
instrumentLogging: boolean
|
|
118
|
-
|
|
119
|
-
// Publisher options.
|
|
120
|
-
|
|
121
|
-
serviceProcessContext?: IServiceProcessContext
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Factory method that adds express routes to the express app object. Used for non-static content.
|
|
125
|
-
* Non-Static content is applied after logging middleware.
|
|
126
|
-
*/
|
|
127
|
-
expressServerRouteFactory?: ExpressRouteFactory
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Factory method that adds express routes to the express app object for static content.
|
|
131
|
-
* Static content is applied before logging middleware.
|
|
132
|
-
*/
|
|
133
|
-
expressServerRouteStaticFactory?: ExpressRouteFactory
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Determines whether the service will monitor its own health via the /latency API endpoint.
|
|
137
|
-
* Note: The service must implement the /latency end-point for this to work.
|
|
138
|
-
*/
|
|
139
|
-
useLatency: boolean
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Determines whether this service is going to need database access.
|
|
143
|
-
*/
|
|
144
|
-
useDatabase: boolean
|
|
145
|
-
|
|
146
|
-
instrumentationObservationInterval: number
|
|
147
|
-
|
|
148
|
-
instrumentationTimeWindow: number
|
|
149
|
-
|
|
150
|
-
useRedisAdaptor: boolean
|
|
151
|
-
|
|
152
|
-
redisAdaptorUrl?: string
|
|
153
|
-
|
|
154
|
-
useRedisInstrumentationTransport?: boolean
|
|
155
|
-
|
|
156
|
-
redisInstrumentationTransportUrl?: string
|
|
157
|
-
|
|
158
|
-
workerExec?: string
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Is this application using nodejs cluster mode?
|
|
162
|
-
*/
|
|
163
|
-
clusterMode: boolean
|
|
164
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/* eslint @typescript-eslint/no-explicit-any: 0, @typescript-eslint/no-unused-vars: 0 */ // --> OFF
|
|
2
|
-
|
|
3
|
-
//import Debug from "debug";
|
|
4
|
-
//const debug = Debug(`proc:${process.pid}:PublishRESTServer`);
|
|
5
|
-
|
|
6
|
-
import { IPublisherTransport, IInstrumentPayload } from '@nsshunt/stspublisherserver'
|
|
7
|
-
import { IMKafkaManager } from './../kafka/IMKafkaManager'
|
|
8
|
-
import { InfluxDBManager } from './../influxdb/influxDBManager'
|
|
9
|
-
|
|
10
|
-
import { PublishTransportUtils } from './publishTransportUtils'
|
|
11
|
-
|
|
12
|
-
export class PublishTransportDirect implements IPublisherTransport
|
|
13
|
-
{
|
|
14
|
-
#influxDBManager: InfluxDBManager;
|
|
15
|
-
#IMkafkaManager: IMKafkaManager;
|
|
16
|
-
|
|
17
|
-
constructor()
|
|
18
|
-
{
|
|
19
|
-
this.#influxDBManager = new InfluxDBManager();
|
|
20
|
-
this.#IMkafkaManager = new IMKafkaManager();
|
|
21
|
-
this.#IMkafkaManager.Start();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// Returns true for success or false for failure.
|
|
25
|
-
Publish = async (payload: IInstrumentPayload): Promise<boolean> =>
|
|
26
|
-
{
|
|
27
|
-
try {
|
|
28
|
-
const updatedContext = PublishTransportUtils.GetServiceContext(payload.context.nid);
|
|
29
|
-
payload.context = updatedContext as any;
|
|
30
|
-
|
|
31
|
-
//this.#SendIPCMessageToMaster(InstrumentManagerEventName.UPDATE_INSTRUMENT_DATA, instrumentPayload)
|
|
32
|
-
this.#influxDBManager.OutputInfluxDB(payload);
|
|
33
|
-
this.#IMkafkaManager.OutputLogs(payload);
|
|
34
|
-
|
|
35
|
-
return true;
|
|
36
|
-
} catch (error)
|
|
37
|
-
{
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
async Close(): Promise<boolean> {
|
|
43
|
-
return true;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { ServiceProcessContext } from './../commonTypes'
|
|
2
|
-
import { ModelDelimeter } from '@nsshunt/stsutils'
|
|
3
|
-
|
|
4
|
-
export class PublishTransportUtils
|
|
5
|
-
{
|
|
6
|
-
static GetServiceContext(nid: string): ServiceProcessContext {
|
|
7
|
-
// Return null if no context is required
|
|
8
|
-
//return null;
|
|
9
|
-
if (nid === ModelDelimeter.ROOT) {
|
|
10
|
-
return { root: ModelDelimeter.ROOT };
|
|
11
|
-
}
|
|
12
|
-
const context: ServiceProcessContext = { nid };
|
|
13
|
-
const idsplit = nid.split(ModelDelimeter.SEPERATOR);
|
|
14
|
-
|
|
15
|
-
const serviceId = idsplit[0];
|
|
16
|
-
const serviceInstanceId = idsplit[1].split(ModelDelimeter.NID_SEPERATOR)[0];
|
|
17
|
-
const serviceInstanceProcessId = idsplit[1].split(ModelDelimeter.NID_SEPERATOR)[1];
|
|
18
|
-
|
|
19
|
-
const serviceIdSplit = serviceId.split(ModelDelimeter.COMPONENT_SEPERATOR);
|
|
20
|
-
const serviceName =serviceIdSplit[0]; // Defined in .env or environment variable
|
|
21
|
-
const serviceVersion = serviceIdSplit[1]; // Defined in .env or environment variable
|
|
22
|
-
|
|
23
|
-
context.serviceId = serviceId; // Service name and the service version
|
|
24
|
-
|
|
25
|
-
if (typeof serviceInstanceId != 'undefined') {
|
|
26
|
-
const serviceInstanceIdSplit = serviceInstanceId.split(ModelDelimeter.COMPONENT_SEPERATOR);
|
|
27
|
-
const sid = serviceInstanceIdSplit[0];
|
|
28
|
-
const hostName = serviceInstanceIdSplit[1];
|
|
29
|
-
|
|
30
|
-
context.serviceInstanceId = serviceInstanceId; // Service unique id and the host name
|
|
31
|
-
context.sid = sid; // Service unique id only, does not include host
|
|
32
|
-
context.hostName = hostName; // Service Instance Host Name
|
|
33
|
-
|
|
34
|
-
if (typeof serviceInstanceProcessId != 'undefined') {
|
|
35
|
-
const serviceInstanceProcessIdSplit = serviceInstanceProcessId.split(ModelDelimeter.COMPONENT_SEPERATOR);
|
|
36
|
-
const pid = parseInt(serviceInstanceProcessIdSplit[0]);
|
|
37
|
-
const ppid = parseInt(serviceInstanceProcessIdSplit[1]);
|
|
38
|
-
const isMaster = (pid === ppid ? true : false);
|
|
39
|
-
|
|
40
|
-
context.serviceInstanceProcessId = serviceInstanceProcessId; // Service Instance OS Process ID (parent process id)
|
|
41
|
-
context.pid = pid; // Service Instance OS Process ID (parent process id)
|
|
42
|
-
context.ppid = ppid; // Service Instance OS Parent Process ID if worker. Will be pid if parent process.
|
|
43
|
-
context.isMaster = isMaster; // True if is Master Process
|
|
44
|
-
context.isWorker = !isMaster; // True if is Worker Process
|
|
45
|
-
context.serviceName = serviceName; // Defined in .env or environment variable
|
|
46
|
-
context.serviceVersion = serviceVersion; // Defined in .env or environment variable
|
|
47
|
-
context.serviceInstanceId = serviceInstanceId; // unique service id with host
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return context;
|
|
52
|
-
}
|
|
53
|
-
}
|
package/src_working/server.ts
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
/* eslint @typescript-eslint/no-explicit-any: 0, @typescript-eslint/no-unused-vars: 0 */ // --> OFF
|
|
2
|
-
import express, { Express, Request, Response, NextFunction } from 'express';
|
|
3
|
-
|
|
4
|
-
import cors from 'cors';
|
|
5
|
-
import cookieParser from 'cookie-parser';
|
|
6
|
-
|
|
7
|
-
import { RequestLoggerMiddleware, RequestLoggerMiddlewareEventName } from '@nsshunt/stspublisherserver'
|
|
8
|
-
|
|
9
|
-
import { ProcessOptions } from './processoptions'
|
|
10
|
-
|
|
11
|
-
import { $Options } from '@nsshunt/stsconfig'
|
|
12
|
-
const goptions = $Options()
|
|
13
|
-
|
|
14
|
-
import { IProcessBase } from './commonTypes'
|
|
15
|
-
import { Gauge, InstrumentGaugeTelemetry, InstrumentHistogramTelemetry, InstrumentVelocityTelemetry } from '@nsshunt/stsinstrumentation'
|
|
16
|
-
|
|
17
|
-
import { ISocketRecord, ServerNetworkMiddleware, ServerNetworkMiddlewareEventName } from './middleware/serverNetworkMiddleware'
|
|
18
|
-
|
|
19
|
-
export class STSExpressServer
|
|
20
|
-
{
|
|
21
|
-
#app: Express;
|
|
22
|
-
|
|
23
|
-
constructor(options: ProcessOptions, stsApp: IProcessBase)
|
|
24
|
-
{
|
|
25
|
-
// Standard RequestLoggerMiddleware for all STS services
|
|
26
|
-
const requestLoggerMiddleware = new RequestLoggerMiddleware({
|
|
27
|
-
ignoresocketio: goptions.ignoresocketio
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
const serverNetworkMiddleware = new ServerNetworkMiddleware({
|
|
31
|
-
name: (stsApp.options as ProcessOptions).serviceName,
|
|
32
|
-
outputDebug: false
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
serverNetworkMiddleware.on(ServerNetworkMiddlewareEventName.UpdateInstrument_SERVER_NET_VAL, (data: ISocketRecord) => {
|
|
36
|
-
//console.log(`serverNetworkMiddleware: [${JSON.stringify(data)}]`.magenta)
|
|
37
|
-
stsApp.UpdateInstrument(Gauge.NETWORK_RX_GAUGE, {
|
|
38
|
-
Inc: data.requestBytesRead
|
|
39
|
-
} as InstrumentGaugeTelemetry);
|
|
40
|
-
|
|
41
|
-
stsApp.UpdateInstrument(Gauge.NETWORK_TX_GAUGE, {
|
|
42
|
-
Inc: data.requestBytesWritten
|
|
43
|
-
} as InstrumentGaugeTelemetry);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
requestLoggerMiddleware.on(RequestLoggerMiddlewareEventName.UpdateInstrument_AR_INC, () => {
|
|
47
|
-
stsApp.UpdateInstrument(Gauge.ACTIVE_REQUEST_GAUGE, {
|
|
48
|
-
Inc: 1
|
|
49
|
-
} as InstrumentGaugeTelemetry);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
requestLoggerMiddleware.on(RequestLoggerMiddlewareEventName.UpdateInstrument_AR_DEC, () => {
|
|
53
|
-
stsApp.UpdateInstrument(Gauge.ACTIVE_REQUEST_GAUGE, {
|
|
54
|
-
Dec: 1
|
|
55
|
-
} as InstrumentGaugeTelemetry);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
requestLoggerMiddleware.on(RequestLoggerMiddlewareEventName.UpdateInstrument_DH_VAL, (timeInMs) => {
|
|
59
|
-
stsApp.UpdateInstrument(Gauge.DURATION_HISTOGRAM_GAUGE, {
|
|
60
|
-
val: timeInMs
|
|
61
|
-
} as InstrumentHistogramTelemetry);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
requestLoggerMiddleware.on(RequestLoggerMiddlewareEventName.UpdateInstrument_D_VAL, (timeInMs) => {
|
|
65
|
-
stsApp.UpdateInstrument(Gauge.DURATION_GAUGE, {
|
|
66
|
-
val: timeInMs
|
|
67
|
-
} as InstrumentHistogramTelemetry);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
requestLoggerMiddleware.on(RequestLoggerMiddlewareEventName.UpdateInstrument_RC_INC, () => {
|
|
71
|
-
stsApp.UpdateInstrument(Gauge.REQUEST_COUNT_GAUGE, {
|
|
72
|
-
Inc: 1
|
|
73
|
-
} as InstrumentGaugeTelemetry);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
requestLoggerMiddleware.on(RequestLoggerMiddlewareEventName.UpdateInstrument_V_INC, () => {
|
|
77
|
-
if (stsApp.InstrumentExists(Gauge.VELOCITY_GAUGE)) {
|
|
78
|
-
stsApp.UpdateInstrument(Gauge.VELOCITY_GAUGE, {
|
|
79
|
-
Inc: 1
|
|
80
|
-
} as InstrumentVelocityTelemetry);
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
const app = express();
|
|
85
|
-
this.#app = app;
|
|
86
|
-
|
|
87
|
-
// https://stackoverflow.com/questions/19743396/cors-cannot-use-wildcard-in-access-control-allow-origin-when-credentials-flag-i
|
|
88
|
-
// See answer from Christoph Hansen is thread above ...
|
|
89
|
-
// https://expressjs.com/en/resources/middleware/cors.html
|
|
90
|
-
const corsConfig = {
|
|
91
|
-
credentials: true,
|
|
92
|
-
origin: true,
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
app.use(cors(corsConfig));
|
|
96
|
-
|
|
97
|
-
app.use(cookieParser())
|
|
98
|
-
|
|
99
|
-
app.use(express.urlencoded({ extended: false, limit: goptions.maxPayloadSize }));
|
|
100
|
-
|
|
101
|
-
app.use(express.json({limit: goptions.maxPayloadSize}));
|
|
102
|
-
|
|
103
|
-
// Allow the static SPA to also be servered by this app
|
|
104
|
-
//app.use('/static', express.static(path.join(__dirname, 'public')))
|
|
105
|
-
if (options.expressServerRouteStaticFactory) {
|
|
106
|
-
options.expressServerRouteStaticFactory(app, stsApp);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
app.use(requestLoggerMiddleware.Middleware.bind(requestLoggerMiddleware));
|
|
110
|
-
|
|
111
|
-
app.use(serverNetworkMiddleware.Middleware.bind(serverNetworkMiddleware));
|
|
112
|
-
|
|
113
|
-
if (options.expressServerRouteFactory) {
|
|
114
|
-
options.expressServerRouteFactory(app, stsApp);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// Express error handling fall-back
|
|
118
|
-
app.use(function(err: any, req: Request, res: Response, next: NextFunction) {
|
|
119
|
-
//@@ add to errors metric here - perhaps break down by type
|
|
120
|
-
|
|
121
|
-
if (err) {
|
|
122
|
-
//@@console.log(err);
|
|
123
|
-
res.status(err.status).send(err);
|
|
124
|
-
} else {
|
|
125
|
-
next();
|
|
126
|
-
}
|
|
127
|
-
/*
|
|
128
|
-
if(err.name === 'UnauthorizedError') {
|
|
129
|
-
res.status(401).send(err);
|
|
130
|
-
} else {
|
|
131
|
-
next();
|
|
132
|
-
}
|
|
133
|
-
*/
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
get App(): Express
|
|
138
|
-
{
|
|
139
|
-
return this.#app;
|
|
140
|
-
}
|
|
141
|
-
}
|