@flexent/stack-backend 2.0.0
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/out/main/BaseApp.d.ts +41 -0
- package/out/main/BaseApp.js +128 -0
- package/out/main/BaseApp.js.map +1 -0
- package/out/main/MetaHandler.d.ts +7 -0
- package/out/main/MetaHandler.js +29 -0
- package/out/main/MetaHandler.js.map +1 -0
- package/out/main/MetaHttpServer.d.ts +16 -0
- package/out/main/MetaHttpServer.js +41 -0
- package/out/main/MetaHttpServer.js.map +1 -0
- package/out/main/MetaRouter.d.ts +7 -0
- package/out/main/MetaRouter.js +49 -0
- package/out/main/MetaRouter.js.map +1 -0
- package/out/main/ProcessMetrics.d.ts +9 -0
- package/out/main/ProcessMetrics.js +41 -0
- package/out/main/ProcessMetrics.js.map +1 -0
- package/out/main/ProcessSignals.d.ts +12 -0
- package/out/main/ProcessSignals.js +47 -0
- package/out/main/ProcessSignals.js.map +1 -0
- package/out/main/StandardLogger.d.ts +8 -0
- package/out/main/StandardLogger.js +39 -0
- package/out/main/StandardLogger.js.map +1 -0
- package/out/main/index.d.ts +10 -0
- package/out/main/index.js +11 -0
- package/out/main/index.js.map +1 -0
- package/out/main/utils/deps.d.ts +2 -0
- package/out/main/utils/deps.js +8 -0
- package/out/main/utils/deps.js.map +1 -0
- package/out/main/utils/env.d.ts +4 -0
- package/out/main/utils/env.js +31 -0
- package/out/main/utils/env.js.map +1 -0
- package/out/main/utils/status.d.ts +3 -0
- package/out/main/utils/status.js +14 -0
- package/out/main/utils/status.js.map +1 -0
- package/package.json +23 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import { HttpServer } from '@flexent/http-server';
|
|
3
|
+
import { Logger } from '@flexent/logger';
|
|
4
|
+
import { ProcessEnvConfig } from 'mesh-config';
|
|
5
|
+
import { Mesh } from 'mesh-ioc';
|
|
6
|
+
import { MetaHttpServer } from './MetaHttpServer.js';
|
|
7
|
+
import { ProcessSignals } from './ProcessSignals.js';
|
|
8
|
+
/**
|
|
9
|
+
* Common application setup with Mesh IoC, logger, metrics and start/stop hooks.
|
|
10
|
+
*/
|
|
11
|
+
export declare abstract class BaseApp {
|
|
12
|
+
logger: Logger;
|
|
13
|
+
processEnvConfig: ProcessEnvConfig;
|
|
14
|
+
httpServer: HttpServer;
|
|
15
|
+
metaHttpServer: MetaHttpServer;
|
|
16
|
+
processSignals: ProcessSignals;
|
|
17
|
+
mesh: Mesh;
|
|
18
|
+
constructor();
|
|
19
|
+
createHttpScope(): Mesh;
|
|
20
|
+
createMetaScope(): Mesh;
|
|
21
|
+
/**
|
|
22
|
+
* Application initialization code.
|
|
23
|
+
* Called on production startup and during tests.
|
|
24
|
+
*/
|
|
25
|
+
start(): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Application shutdown code.
|
|
28
|
+
* Called when production app gracefully terminates and during tests.
|
|
29
|
+
*/
|
|
30
|
+
stop(): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* The method called by application entrypoint.
|
|
33
|
+
* Tests do not use that.
|
|
34
|
+
*/
|
|
35
|
+
run(): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Called on SIGTERM/SIGINT, when the app is running using `run()`.
|
|
38
|
+
* Tests do not use that.
|
|
39
|
+
*/
|
|
40
|
+
shutdown(): Promise<void>;
|
|
41
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import 'reflect-metadata';
|
|
11
|
+
import { RouteMetrics } from '@flexent/http-router';
|
|
12
|
+
import { HttpCorsHandler, HttpErrorHandler, HttpHandler, HttpServer } from '@flexent/http-server';
|
|
13
|
+
import { Logger } from '@flexent/logger';
|
|
14
|
+
import { Config, ProcessEnvConfig } from 'mesh-config';
|
|
15
|
+
import { dep, Mesh } from 'mesh-ioc';
|
|
16
|
+
import { MetaHandler } from './MetaHandler.js';
|
|
17
|
+
import { MetaHttpServer } from './MetaHttpServer.js';
|
|
18
|
+
import { MetaRouter } from './MetaRouter.js';
|
|
19
|
+
import { ProcessMetrics } from './ProcessMetrics.js';
|
|
20
|
+
import { ProcessSignals } from './ProcessSignals.js';
|
|
21
|
+
import { StandardLogger } from './StandardLogger.js';
|
|
22
|
+
import { assertMissingDeps } from './utils/deps.js';
|
|
23
|
+
import { configureEnv, getEnvName } from './utils/env.js';
|
|
24
|
+
const process = global.process;
|
|
25
|
+
/**
|
|
26
|
+
* Common application setup with Mesh IoC, logger, metrics and start/stop hooks.
|
|
27
|
+
*/
|
|
28
|
+
export class BaseApp {
|
|
29
|
+
constructor() {
|
|
30
|
+
this.mesh = new Mesh();
|
|
31
|
+
this.mesh.connect(this);
|
|
32
|
+
this.mesh.service(ProcessEnvConfig);
|
|
33
|
+
this.mesh.alias(Config, ProcessEnvConfig);
|
|
34
|
+
this.mesh.service(StandardLogger);
|
|
35
|
+
this.mesh.alias(Logger, StandardLogger);
|
|
36
|
+
this.mesh.service(ProcessSignals);
|
|
37
|
+
this.mesh.service(RouteMetrics);
|
|
38
|
+
this.mesh.service(ProcessMetrics);
|
|
39
|
+
this.mesh.service(HttpServer);
|
|
40
|
+
this.mesh.service(MetaHttpServer);
|
|
41
|
+
// Global Handlers
|
|
42
|
+
this.mesh.service(HttpCorsHandler);
|
|
43
|
+
this.mesh.service(HttpErrorHandler);
|
|
44
|
+
// Scopes
|
|
45
|
+
this.mesh.scope('HttpScope', () => this.createHttpScope());
|
|
46
|
+
this.mesh.scope('MetaScope', () => this.createMetaScope());
|
|
47
|
+
}
|
|
48
|
+
createHttpScope() {
|
|
49
|
+
const scope = new Mesh('Http', this.mesh);
|
|
50
|
+
return scope;
|
|
51
|
+
}
|
|
52
|
+
createMetaScope() {
|
|
53
|
+
const scope = new Mesh('Meta', this.mesh);
|
|
54
|
+
this.mesh.service(MetaRouter);
|
|
55
|
+
this.mesh.service(HttpHandler, MetaHandler);
|
|
56
|
+
return scope;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Application initialization code.
|
|
60
|
+
* Called on production startup and during tests.
|
|
61
|
+
*/
|
|
62
|
+
async start() {
|
|
63
|
+
const env = getEnvName();
|
|
64
|
+
configureEnv(env);
|
|
65
|
+
this.processEnvConfig.refresh();
|
|
66
|
+
this.logger.info('Starting application', { env });
|
|
67
|
+
assertMissingDeps(this.mesh);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Application shutdown code.
|
|
71
|
+
* Called when production app gracefully terminates and during tests.
|
|
72
|
+
*/
|
|
73
|
+
async stop() {
|
|
74
|
+
this.logger.info('Stopping application');
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The method called by application entrypoint.
|
|
78
|
+
* Tests do not use that.
|
|
79
|
+
*/
|
|
80
|
+
async run() {
|
|
81
|
+
try {
|
|
82
|
+
this.processSignals.installSignalHandlers();
|
|
83
|
+
this.processSignals.onStopRequested.on(() => this.shutdown(), this);
|
|
84
|
+
await this.start();
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
this.logger.error(`Failed to start ${this.constructor.name}`, { error });
|
|
88
|
+
process.exit(1);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Called on SIGTERM/SIGINT, when the app is running using `run()`.
|
|
93
|
+
* Tests do not use that.
|
|
94
|
+
*/
|
|
95
|
+
async shutdown() {
|
|
96
|
+
try {
|
|
97
|
+
this.processSignals.uninstallSignalHandlers();
|
|
98
|
+
this.processSignals.onStopRequested.removeAll(this);
|
|
99
|
+
await this.stop();
|
|
100
|
+
process.exit(0);
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
this.logger.error(`Failed to stop ${this.constructor.name}`, { error });
|
|
104
|
+
process.exit(1);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
__decorate([
|
|
109
|
+
dep(),
|
|
110
|
+
__metadata("design:type", Logger)
|
|
111
|
+
], BaseApp.prototype, "logger", void 0);
|
|
112
|
+
__decorate([
|
|
113
|
+
dep(),
|
|
114
|
+
__metadata("design:type", ProcessEnvConfig)
|
|
115
|
+
], BaseApp.prototype, "processEnvConfig", void 0);
|
|
116
|
+
__decorate([
|
|
117
|
+
dep(),
|
|
118
|
+
__metadata("design:type", HttpServer)
|
|
119
|
+
], BaseApp.prototype, "httpServer", void 0);
|
|
120
|
+
__decorate([
|
|
121
|
+
dep(),
|
|
122
|
+
__metadata("design:type", MetaHttpServer)
|
|
123
|
+
], BaseApp.prototype, "metaHttpServer", void 0);
|
|
124
|
+
__decorate([
|
|
125
|
+
dep(),
|
|
126
|
+
__metadata("design:type", ProcessSignals)
|
|
127
|
+
], BaseApp.prototype, "processSignals", void 0);
|
|
128
|
+
//# sourceMappingURL=BaseApp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseApp.js","sourceRoot":"","sources":["../../src/main/BaseApp.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,kBAAkB,CAAC;AAE1B,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,WAAW,EAAE,UA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AAgB;iDAAC;AACpC;IAAN,GAAG,EAAE;8BAAc,UAAU;2CAAC;AACxB;IAAN,GAAG,EAAE;8BAAkB,cAAc;+CAAC;AAChC;IAAN,GAAG,EAAE;8BAAkB,cAAc;+CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { HttpChain, type HttpErrorHandler } from '@flexent/http-server';
|
|
2
|
+
import { type MetaRouter } from './MetaRouter.js';
|
|
3
|
+
export declare class MetaHandler extends HttpChain {
|
|
4
|
+
protected errorHandler: HttpErrorHandler;
|
|
5
|
+
protected metaRouter: MetaRouter;
|
|
6
|
+
handlers: (MetaRouter | HttpErrorHandler)[];
|
|
7
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { HttpChain } from '@flexent/http-server';
|
|
11
|
+
import { dep } from 'mesh-ioc';
|
|
12
|
+
export class MetaHandler extends HttpChain {
|
|
13
|
+
constructor() {
|
|
14
|
+
super(...arguments);
|
|
15
|
+
this.handlers = [
|
|
16
|
+
this.errorHandler,
|
|
17
|
+
this.metaRouter,
|
|
18
|
+
];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
__decorate([
|
|
22
|
+
dep(),
|
|
23
|
+
__metadata("design:type", Function)
|
|
24
|
+
], MetaHandler.prototype, "errorHandler", void 0);
|
|
25
|
+
__decorate([
|
|
26
|
+
dep(),
|
|
27
|
+
__metadata("design:type", Function)
|
|
28
|
+
], MetaHandler.prototype, "metaRouter", void 0);
|
|
29
|
+
//# sourceMappingURL=MetaHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MetaHandler.js","sourceRoot":"","sources":["../../src/main/MetaHandler.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAyB,MAAM,sBAAsB,CAAC;AACxE,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAI/B,MAAM,OAAO,WAAY,SAAQ,SAAS;IAA1C;;QAKI,aAAQ,GAAG;YACP,IAAI,CAAC,YAAY;YACjB,IAAI,CAAC,UAAU;SAClB,CAAC;IAEN,CAAC;CAAA;AARoB;IAAhB,GAAG,EAAE;;iDAA2C;AAChC;IAAhB,GAAG,EAAE;;+CAAmC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { HttpServer } from '@flexent/http-server';
|
|
2
|
+
import { type ScopeProvider } from 'mesh-ioc';
|
|
3
|
+
/**
|
|
4
|
+
* Serves application metadata over HTTP.
|
|
5
|
+
*
|
|
6
|
+
* Most settings inherit main HTTP configuration except:
|
|
7
|
+
*
|
|
8
|
+
* - port is configured with META_HTTP_PORT
|
|
9
|
+
* (it's a good practice to keep meta on a separate port and not expose it to the public)
|
|
10
|
+
* - TLS is not used by default
|
|
11
|
+
*/
|
|
12
|
+
export declare class MetaHttpServer extends HttpServer {
|
|
13
|
+
META_HTTP_PORT: number;
|
|
14
|
+
protected createScope: ScopeProvider;
|
|
15
|
+
constructor();
|
|
16
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { HttpServer } from '@flexent/http-server';
|
|
11
|
+
import { config } from 'mesh-config';
|
|
12
|
+
import { scope } from 'mesh-ioc';
|
|
13
|
+
/**
|
|
14
|
+
* Serves application metadata over HTTP.
|
|
15
|
+
*
|
|
16
|
+
* Most settings inherit main HTTP configuration except:
|
|
17
|
+
*
|
|
18
|
+
* - port is configured with META_HTTP_PORT
|
|
19
|
+
* (it's a good practice to keep meta on a separate port and not expose it to the public)
|
|
20
|
+
* - TLS is not used by default
|
|
21
|
+
*/
|
|
22
|
+
export class MetaHttpServer extends HttpServer {
|
|
23
|
+
constructor() {
|
|
24
|
+
super();
|
|
25
|
+
this.config.port = this.META_HTTP_PORT;
|
|
26
|
+
this.config.shutdownDelay = 0;
|
|
27
|
+
this.config.tlsCert = '';
|
|
28
|
+
this.config.tlsKey = '';
|
|
29
|
+
this.config.tlsCa = '';
|
|
30
|
+
this.config.tlsCiphers = '';
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
__decorate([
|
|
34
|
+
config({ default: 8081 }),
|
|
35
|
+
__metadata("design:type", Number)
|
|
36
|
+
], MetaHttpServer.prototype, "META_HTTP_PORT", void 0);
|
|
37
|
+
__decorate([
|
|
38
|
+
scope('MetaScope'),
|
|
39
|
+
__metadata("design:type", Function)
|
|
40
|
+
], MetaHttpServer.prototype, "createScope", void 0);
|
|
41
|
+
//# sourceMappingURL=MetaHttpServer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MetaHttpServer.js","sourceRoot":"","sources":["../../src/main/MetaHttpServer.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,EAAsB,MAAM,UAAU,CAAC;AAErD;;;;;;;;GAQG;AACH,MAAM,OAAO,cAAe,SAAQ,UAAU;IAQ1C;QACI,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,cAAc,CAAC;QACvC,IAAI,CAAC,MAAM,CAAC,aAAa,GAAG,CAAC,CAAC;QAC9B,IAAI,CAAC,MAAM,CAAC,OAAO,GAAG,EAAE,CAAC;QACzB,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,EAAE,CAAC;QACxB,IAAI,CAAC,MAAM,CAAC,KAAK,GAAG,EAAE,CAAC;QACvB,IAAI,CAAC,MAAM,CAAC,UAAU,GAAG,EAAE,CAAC;IAChC,CAAC;CAEJ;AAfG;IADC,MAAM,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;sDACF;AAGL;IADlB,KAAK,CAAC,WAAW,CAAC;;mDAC4B"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { HttpRouter } from '@flexent/http-router';
|
|
2
|
+
import { type HttpContext } from '@flexent/http-server';
|
|
3
|
+
export declare class MetaRouter extends HttpRouter {
|
|
4
|
+
private mesh;
|
|
5
|
+
getStatus(ctx: HttpContext): Promise<void>;
|
|
6
|
+
getMetrics(ctx: HttpContext): Promise<void>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import fs from 'node:fs';
|
|
11
|
+
import { Get, HttpRouter } from '@flexent/http-router';
|
|
12
|
+
import { generateMetricsReport } from '@flexent/metrics';
|
|
13
|
+
import { dep } from 'mesh-ioc';
|
|
14
|
+
import { invokeStatusChecks } from './utils/status.js';
|
|
15
|
+
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf-8'));
|
|
16
|
+
export class MetaRouter extends HttpRouter {
|
|
17
|
+
async getStatus(ctx) {
|
|
18
|
+
const checks = await invokeStatusChecks(this.mesh);
|
|
19
|
+
ctx.responseBody = {
|
|
20
|
+
version: pkg.version,
|
|
21
|
+
...checks,
|
|
22
|
+
};
|
|
23
|
+
ctx.status = 200;
|
|
24
|
+
ctx.log = false;
|
|
25
|
+
}
|
|
26
|
+
async getMetrics(ctx) {
|
|
27
|
+
const report = generateMetricsReport(this.mesh);
|
|
28
|
+
ctx.status = 200;
|
|
29
|
+
ctx.responseBody = report;
|
|
30
|
+
ctx.log = false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
__decorate([
|
|
34
|
+
dep(),
|
|
35
|
+
__metadata("design:type", Function)
|
|
36
|
+
], MetaRouter.prototype, "mesh", void 0);
|
|
37
|
+
__decorate([
|
|
38
|
+
Get({ path: '/status' }),
|
|
39
|
+
__metadata("design:type", Function),
|
|
40
|
+
__metadata("design:paramtypes", [Function]),
|
|
41
|
+
__metadata("design:returntype", Promise)
|
|
42
|
+
], MetaRouter.prototype, "getStatus", null);
|
|
43
|
+
__decorate([
|
|
44
|
+
Get({ path: '/metrics' }),
|
|
45
|
+
__metadata("design:type", Function),
|
|
46
|
+
__metadata("design:paramtypes", [Function]),
|
|
47
|
+
__metadata("design:returntype", Promise)
|
|
48
|
+
], MetaRouter.prototype, "getMetrics", null);
|
|
49
|
+
//# sourceMappingURL=MetaRouter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MetaRouter.js","sourceRoot":"","sources":["../../src/main/MetaRouter.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AAEzB,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,GAAG,EAAa,MAAM,UAAU,CAAC;AAE1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEvD,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC,CAAC;AAEjE,MAAM,OAAO,UAAW,SAAQ,UAAU;IAKhC,AAAN,KAAK,CAAC,SAAS,CAAC,GAAgB;QAC5B,MAAM,MAAM,GAAG,MAAM,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACnD,GAAG,CAAC,YAAY,GAAG;YACf,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,GAAG,MAAM;SACZ,CAAC;QACF,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC;QACjB,GAAG,CAAC,GAAG,GAAG,KAAK,CAAC;IACpB,CAAC;IAGK,AAAN,KAAK,CAAC,UAAU,CAAC,GAAgB;QAC7B,MAAM,MAAM,GAAG,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAChD,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC;QACjB,GAAG,CAAC,YAAY,GAAG,MAAM,CAAC;QAC1B,GAAG,CAAC,GAAG,GAAG,KAAK,CAAC;IACpB,CAAC;CAEJ;AArBkB;IAAd,GAAG,EAAE;;wCAAqB;AAGrB;IADL,GAAG,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;;;;2CASxB;AAGK;IADL,GAAG,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;;;;4CAMzB"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { DynamicGaugeMetric, metric } from '@flexent/metrics';
|
|
11
|
+
const process = global.process;
|
|
12
|
+
export class ProcessMetrics {
|
|
13
|
+
constructor() {
|
|
14
|
+
this.cpuUsage = new DynamicGaugeMetric(() => {
|
|
15
|
+
const cpuUsage = process.cpuUsage();
|
|
16
|
+
return [
|
|
17
|
+
{ labels: { type: 'user' }, value: cpuUsage.user },
|
|
18
|
+
{ labels: { type: 'system' }, value: cpuUsage.system },
|
|
19
|
+
];
|
|
20
|
+
}, 'app_process_cpu_usage', 'Process Memory Usage');
|
|
21
|
+
this.memoryUsage = new DynamicGaugeMetric(() => {
|
|
22
|
+
const memoryUsage = process.memoryUsage();
|
|
23
|
+
return [
|
|
24
|
+
{ labels: { type: 'rss' }, value: memoryUsage.rss },
|
|
25
|
+
{ labels: { type: 'heapUsed' }, value: memoryUsage.heapUsed },
|
|
26
|
+
{ labels: { type: 'heapTotal' }, value: memoryUsage.heapTotal },
|
|
27
|
+
{ labels: { type: 'arrayBuffers' }, value: memoryUsage.arrayBuffers },
|
|
28
|
+
{ labels: { type: 'external' }, value: memoryUsage.external },
|
|
29
|
+
];
|
|
30
|
+
}, 'app_process_memory_usage', 'Process Memory Usage');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
__decorate([
|
|
34
|
+
metric(),
|
|
35
|
+
__metadata("design:type", Object)
|
|
36
|
+
], ProcessMetrics.prototype, "cpuUsage", void 0);
|
|
37
|
+
__decorate([
|
|
38
|
+
metric(),
|
|
39
|
+
__metadata("design:type", Object)
|
|
40
|
+
], ProcessMetrics.prototype, "memoryUsage", void 0);
|
|
41
|
+
//# sourceMappingURL=ProcessMetrics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProcessMetrics.js","sourceRoot":"","sources":["../../src/main/ProcessMetrics.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE9D,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;AAE/B,MAAM,OAAO,cAAc;IAA3B;QAGI,aAAQ,GAAG,IAAI,kBAAkB,CAAmB,GAAG,EAAE;YACrD,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;YACpC,OAAO;gBACH,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,QAAQ,CAAC,IAAI,EAAE;gBAClD,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,KAAK,EAAE,QAAQ,CAAC,MAAM,EAAE;aACzD,CAAC;QACN,CAAC,EAAE,uBAAuB,EAAE,sBAAsB,CAAC,CAAC;QAGpD,gBAAW,GAAG,IAAI,kBAAkB,CAAmB,GAAG,EAAE;YACxD,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;YAC1C,OAAO;gBACH,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,WAAW,CAAC,GAAG,EAAE;gBACnD,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,KAAK,EAAE,WAAW,CAAC,QAAQ,EAAE;gBAC7D,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,KAAK,EAAE,WAAW,CAAC,SAAS,EAAE;gBAC/D,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,EAAE,KAAK,EAAE,WAAW,CAAC,YAAY,EAAE;gBACrE,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,KAAK,EAAE,WAAW,CAAC,QAAQ,EAAE;aAChE,CAAC;QACN,CAAC,EAAE,0BAA0B,EAAE,sBAAsB,CAAC,CAAC;IAE3D,CAAC;CAAA;AApBG;IADC,MAAM,EAAE;;gDAO2C;AAGpD;IADC,MAAM,EAAE;;mDAU8C"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Logger } from '@flexent/logger';
|
|
2
|
+
import { Event } from 'nanoevent';
|
|
3
|
+
export declare class ProcessSignals {
|
|
4
|
+
protected logger: Logger;
|
|
5
|
+
onStopRequested: Event<void>;
|
|
6
|
+
installSignalHandlers(): void;
|
|
7
|
+
uninstallSignalHandlers(): void;
|
|
8
|
+
protected onUnhandledException: (error: unknown) => void;
|
|
9
|
+
protected onUnhandledRejection: (error: unknown) => void;
|
|
10
|
+
protected onSIGTERM: () => void;
|
|
11
|
+
protected onSIGINT: () => void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { dep } from 'mesh-ioc';
|
|
11
|
+
import { Event } from 'nanoevent';
|
|
12
|
+
export class ProcessSignals {
|
|
13
|
+
constructor() {
|
|
14
|
+
this.onStopRequested = new Event();
|
|
15
|
+
this.onUnhandledException = (error) => {
|
|
16
|
+
this.logger.error('uncaughtException', { error });
|
|
17
|
+
};
|
|
18
|
+
this.onUnhandledRejection = (error) => {
|
|
19
|
+
this.logger.error('unhandledRejection', { error });
|
|
20
|
+
};
|
|
21
|
+
this.onSIGTERM = () => {
|
|
22
|
+
this.logger.info('Received SIGTERM');
|
|
23
|
+
this.onStopRequested.emit();
|
|
24
|
+
};
|
|
25
|
+
this.onSIGINT = () => {
|
|
26
|
+
this.logger.info('Received SIGINT');
|
|
27
|
+
this.onStopRequested.emit();
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
installSignalHandlers() {
|
|
31
|
+
process.on('uncaughtException', this.onUnhandledException);
|
|
32
|
+
process.on('unhandledRejection', this.onUnhandledRejection);
|
|
33
|
+
process.on('SIGTERM', this.onSIGTERM);
|
|
34
|
+
process.on('SIGINT', this.onSIGINT);
|
|
35
|
+
}
|
|
36
|
+
uninstallSignalHandlers() {
|
|
37
|
+
process.removeListener('uncaughtException', this.onUnhandledException);
|
|
38
|
+
process.removeListener('unhandledRejection', this.onUnhandledRejection);
|
|
39
|
+
process.removeListener('SIGTERM', this.onSIGTERM);
|
|
40
|
+
process.removeListener('SIGINT', this.onSIGINT);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
__decorate([
|
|
44
|
+
dep(),
|
|
45
|
+
__metadata("design:type", Function)
|
|
46
|
+
], ProcessSignals.prototype, "logger", void 0);
|
|
47
|
+
//# sourceMappingURL=ProcessSignals.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProcessSignals.js","sourceRoot":"","sources":["../../src/main/ProcessSignals.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAElC,MAAM,OAAO,cAAc;IAA3B;QAII,oBAAe,GAAG,IAAI,KAAK,EAAQ,CAAC;QAgB1B,yBAAoB,GAAG,CAAC,KAAc,EAAE,EAAE;YAChD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,mBAAmB,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QACtD,CAAC,CAAC;QAEQ,yBAAoB,GAAG,CAAC,KAAc,EAAE,EAAE;YAChD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,oBAAoB,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QACvD,CAAC,CAAC;QAEQ,cAAS,GAAG,GAAG,EAAE;YACvB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;YACrC,IAAI,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC;QAChC,CAAC,CAAC;QAEQ,aAAQ,GAAG,GAAG,EAAE;YACtB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;YACpC,IAAI,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC;QAChC,CAAC,CAAC;IAEN,CAAC;IAhCG,qBAAqB;QACjB,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,IAAI,CAAC,oBAAoB,CAAC,CAAC;QAC3D,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,IAAI,CAAC,oBAAoB,CAAC,CAAC;QAC5D,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;QACtC,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IACxC,CAAC;IAED,uBAAuB;QACnB,OAAO,CAAC,cAAc,CAAC,mBAAmB,EAAE,IAAI,CAAC,oBAAoB,CAAC,CAAC;QACvE,OAAO,CAAC,cAAc,CAAC,oBAAoB,EAAE,IAAI,CAAC,oBAAoB,CAAC,CAAC;QACxE,OAAO,CAAC,cAAc,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;QAClD,OAAO,CAAC,cAAc,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IACpD,CAAC;CAoBJ;AApCoB;IAAhB,GAAG,EAAE;;8CAA2B"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { Logger, PrettyLogFormatter, StructuredLogFormatter } from '@flexent/logger';
|
|
11
|
+
import { config } from 'mesh-config';
|
|
12
|
+
export class StandardLogger extends Logger {
|
|
13
|
+
constructor() {
|
|
14
|
+
super();
|
|
15
|
+
this.formatter = this.createFormatter();
|
|
16
|
+
this.setLevel(this.LOG_LEVEL);
|
|
17
|
+
}
|
|
18
|
+
createFormatter() {
|
|
19
|
+
if (this.LOG_PRETTY) {
|
|
20
|
+
return new PrettyLogFormatter();
|
|
21
|
+
}
|
|
22
|
+
const fmt = new StructuredLogFormatter();
|
|
23
|
+
fmt.includeStack = this.LOG_STACK;
|
|
24
|
+
return fmt;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
__decorate([
|
|
28
|
+
config({ default: 'info' }),
|
|
29
|
+
__metadata("design:type", String)
|
|
30
|
+
], StandardLogger.prototype, "LOG_LEVEL", void 0);
|
|
31
|
+
__decorate([
|
|
32
|
+
config({ default: false }),
|
|
33
|
+
__metadata("design:type", Boolean)
|
|
34
|
+
], StandardLogger.prototype, "LOG_PRETTY", void 0);
|
|
35
|
+
__decorate([
|
|
36
|
+
config({ default: false }),
|
|
37
|
+
__metadata("design:type", Boolean)
|
|
38
|
+
], StandardLogger.prototype, "LOG_STACK", void 0);
|
|
39
|
+
//# sourceMappingURL=StandardLogger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StandardLogger.js","sourceRoot":"","sources":["../../src/main/StandardLogger.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACrF,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,MAAM,OAAO,cAAe,SAAQ,MAAM;IAMtC;QACI,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;QACxC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAClC,CAAC;IAEO,eAAe;QACnB,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YAClB,OAAO,IAAI,kBAAkB,EAAE,CAAC;QACpC,CAAC;QACD,MAAM,GAAG,GAAG,IAAI,sBAAsB,EAAE,CAAC;QACzC,GAAG,CAAC,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC;QAClC,OAAO,GAAG,CAAC;IACf,CAAC;CAEJ;AAnBgC;IAA5B,MAAM,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;;iDAAoB;AACpB;IAA3B,MAAM,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;;kDAAsB;AACrB;IAA3B,MAAM,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;;iDAAqB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './BaseApp.js';
|
|
2
|
+
export * from './MetaHandler.js';
|
|
3
|
+
export * from './MetaHttpServer.js';
|
|
4
|
+
export * from './MetaRouter.js';
|
|
5
|
+
export * from './ProcessMetrics.js';
|
|
6
|
+
export * from './ProcessSignals.js';
|
|
7
|
+
export * from './StandardLogger.js';
|
|
8
|
+
export * from './utils/deps.js';
|
|
9
|
+
export * from './utils/env.js';
|
|
10
|
+
export * from './utils/status.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from './BaseApp.js';
|
|
2
|
+
export * from './MetaHandler.js';
|
|
3
|
+
export * from './MetaHttpServer.js';
|
|
4
|
+
export * from './MetaRouter.js';
|
|
5
|
+
export * from './ProcessMetrics.js';
|
|
6
|
+
export * from './ProcessSignals.js';
|
|
7
|
+
export * from './StandardLogger.js';
|
|
8
|
+
export * from './utils/deps.js';
|
|
9
|
+
export * from './utils/env.js';
|
|
10
|
+
export * from './utils/status.js';
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/main/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { InitializationError } from '@flexent/errors';
|
|
2
|
+
export function assertMissingDeps(mesh) {
|
|
3
|
+
const missingDepKeys = [...mesh.missingDeps()].map(_ => _.key);
|
|
4
|
+
if (missingDepKeys.length > 0) {
|
|
5
|
+
throw new InitializationError(`The following class dependencies are not found in application global scope: ${missingDepKeys}`);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=deps.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deps.js","sourceRoot":"","sources":["../../../src/main/utils/deps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAGtD,MAAM,UAAU,iBAAiB,CAAC,IAAU;IACxC,MAAM,cAAc,GAAG,CAAC,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAC/D,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,mBAAmB,CAAC,+EAA+E,cAAc,EAAE,CAAC,CAAC;IACnI,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export function getEnvName() {
|
|
2
|
+
if (process.env.NODE_ENV === 'development') {
|
|
3
|
+
return 'development';
|
|
4
|
+
}
|
|
5
|
+
if (process.env.NODE_ENV === 'test') {
|
|
6
|
+
return 'test';
|
|
7
|
+
}
|
|
8
|
+
return 'production';
|
|
9
|
+
}
|
|
10
|
+
export function loadEnvFile(path) {
|
|
11
|
+
try {
|
|
12
|
+
process.loadEnvFile(path);
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
if (error?.code === 'ENOENT') {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
throw error;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export function configureEnv(env) {
|
|
22
|
+
loadEnvFile('.env');
|
|
23
|
+
if (env === 'development') {
|
|
24
|
+
loadEnvFile('.env.dev');
|
|
25
|
+
}
|
|
26
|
+
if (env === 'test') {
|
|
27
|
+
loadEnvFile('.env.test');
|
|
28
|
+
loadEnvFile('.env.dev');
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=env.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.js","sourceRoot":"","sources":["../../../src/main/utils/env.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,UAAU;IACtB,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa,EAAE,CAAC;QACzC,OAAO,aAAa,CAAC;IACzB,CAAC;IACD,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,MAAM,EAAE,CAAC;QAClC,OAAO,MAAM,CAAC;IAClB,CAAC;IACD,OAAO,YAAY,CAAC;AACxB,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,IAAY;IACpC,IAAI,CAAC;QACD,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QAClB,IAAI,KAAK,EAAE,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC3B,OAAO;QACX,CAAC;QACD,MAAM,KAAK,CAAC;IAChB,CAAC;AACL,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,GAAY;IACrC,WAAW,CAAC,MAAM,CAAC,CAAC;IACpB,IAAI,GAAG,KAAK,aAAa,EAAE,CAAC;QACxB,WAAW,CAAC,UAAU,CAAC,CAAC;IAC5B,CAAC;IACD,IAAI,GAAG,KAAK,MAAM,EAAE,CAAC;QACjB,WAAW,CAAC,WAAW,CAAC,CAAC;QACzB,WAAW,CAAC,UAAU,CAAC,CAAC;IAC5B,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createMemberDecorator, findMembers } from 'mesh-decorators';
|
|
2
|
+
const DECORATOR_NAME = '@flexent/http/statusCheck';
|
|
3
|
+
export const statusCheck = createMemberDecorator(DECORATOR_NAME);
|
|
4
|
+
export async function invokeStatusChecks(mesh) {
|
|
5
|
+
const res = {};
|
|
6
|
+
const refs = findMembers(DECORATOR_NAME, mesh);
|
|
7
|
+
const promises = refs.map(ref => ref.target[ref.memberName]());
|
|
8
|
+
const results = await Promise.all(promises);
|
|
9
|
+
for (const [i, ref] of refs.entries()) {
|
|
10
|
+
res[ref.target.constructor.name] = results[i];
|
|
11
|
+
}
|
|
12
|
+
return res;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=status.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"status.js","sourceRoot":"","sources":["../../../src/main/utils/status.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAGrE,MAAM,cAAc,GAAG,2BAA2B,CAAC;AAEnD,MAAM,CAAC,MAAM,WAAW,GAAG,qBAAqB,CAAC,cAAc,CAAC,CAAC;AAEjE,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,IAAU;IAC/C,MAAM,GAAG,GAA2B,EAAE,CAAC;IACvC,MAAM,IAAI,GAAG,WAAW,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;IAC/C,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;IAC/D,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC5C,KAAK,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC;QACpC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAClD,CAAC;IACD,OAAO,GAAG,CAAC;AACf,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@flexent/stack-backend",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Backend basic setup",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./out/main/index.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"out"
|
|
11
|
+
],
|
|
12
|
+
"peerDependencies": {
|
|
13
|
+
"@flexent/errors": "^2.0.0",
|
|
14
|
+
"@flexent/http-router": "^2.0.0",
|
|
15
|
+
"@flexent/http-server": "^2.0.0",
|
|
16
|
+
"@flexent/logger": "^2.0.0",
|
|
17
|
+
"mesh-config": "^1.3.4",
|
|
18
|
+
"mesh-decorators": "^1.3.6",
|
|
19
|
+
"mesh-ioc": "^4.3.1",
|
|
20
|
+
"nanoevent": "^1.0.0",
|
|
21
|
+
"reflect-metadata": "^0.2.2"
|
|
22
|
+
}
|
|
23
|
+
}
|