@wisemen/app-container 2.1.24 → 3.0.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.
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import type { INestApplicationContext } from '@nestjs/common';
|
|
2
|
-
import {
|
|
2
|
+
import { FastifyAdapter } from '@nestjs/platform-fastify';
|
|
3
|
+
import { type FastifyServerOptions } from 'fastify';
|
|
3
4
|
export declare abstract class ProbedContainer {
|
|
4
|
-
private
|
|
5
|
-
private readonly server;
|
|
5
|
+
private adapter?;
|
|
6
6
|
private state;
|
|
7
|
+
private server;
|
|
7
8
|
protected nest?: INestApplicationContext;
|
|
8
|
-
|
|
9
|
+
protected getFastifyOptions(): FastifyServerOptions;
|
|
10
|
+
abstract bootstrap(app: FastifyAdapter): Promise<INestApplicationContext>;
|
|
9
11
|
constructor();
|
|
10
12
|
private _init;
|
|
11
13
|
protected init(): Promise<void>;
|
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
const port = process.env.PORT
|
|
1
|
+
import { FastifyAdapter } from '@nestjs/platform-fastify';
|
|
2
|
+
import { fastify } from 'fastify';
|
|
3
|
+
const port = Number(process.env.PORT) || 3000;
|
|
4
4
|
export class ProbedContainer {
|
|
5
|
-
|
|
6
|
-
server;
|
|
5
|
+
adapter;
|
|
7
6
|
state;
|
|
7
|
+
server;
|
|
8
8
|
nest;
|
|
9
|
+
getFastifyOptions() {
|
|
10
|
+
return {};
|
|
11
|
+
}
|
|
9
12
|
constructor() {
|
|
10
13
|
this.state = 'starting';
|
|
11
|
-
this.app = express();
|
|
12
|
-
this.server = this.app.listen(port, () => {
|
|
13
|
-
console.log('server started');
|
|
14
|
-
});
|
|
15
14
|
this.enableShutdownHooks();
|
|
16
|
-
this.enableProbes();
|
|
17
15
|
void this._init();
|
|
18
16
|
}
|
|
19
17
|
async _init() {
|
|
@@ -27,10 +25,13 @@ export class ProbedContainer {
|
|
|
27
25
|
}
|
|
28
26
|
}
|
|
29
27
|
async init() {
|
|
30
|
-
|
|
31
|
-
adapter
|
|
32
|
-
this.
|
|
28
|
+
this.server = fastify(this.getFastifyOptions());
|
|
29
|
+
this.adapter = new FastifyAdapter(this.server);
|
|
30
|
+
this.enableProbes();
|
|
31
|
+
this.nest = await this.bootstrap(this.adapter);
|
|
33
32
|
await this.nest.init();
|
|
33
|
+
await this.server.listen({ port, host: '0.0.0.0' });
|
|
34
|
+
console.log('Server listening on port', port);
|
|
34
35
|
this.state = 'ready';
|
|
35
36
|
}
|
|
36
37
|
async close() {
|
|
@@ -39,14 +40,6 @@ export class ProbedContainer {
|
|
|
39
40
|
}
|
|
40
41
|
this.state = 'shutdown';
|
|
41
42
|
try {
|
|
42
|
-
await new Promise((resolve, reject) => {
|
|
43
|
-
this.server.close((err) => {
|
|
44
|
-
if (err)
|
|
45
|
-
reject(err);
|
|
46
|
-
else
|
|
47
|
-
resolve();
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
43
|
await this.nest?.close();
|
|
51
44
|
console.log('application closed');
|
|
52
45
|
}
|
|
@@ -63,41 +56,36 @@ export class ProbedContainer {
|
|
|
63
56
|
process.on('exit', () => void this.close());
|
|
64
57
|
}
|
|
65
58
|
enableProbes() {
|
|
66
|
-
this.
|
|
59
|
+
if (this.server == null)
|
|
60
|
+
return;
|
|
61
|
+
this.server.get('/', (_, res) => {
|
|
67
62
|
this.version(res);
|
|
68
63
|
});
|
|
69
|
-
this.
|
|
64
|
+
this.server.get('/health', (_, res) => {
|
|
70
65
|
this.liveness(res);
|
|
71
66
|
});
|
|
72
|
-
this.
|
|
67
|
+
this.server.get('/ready', (_, res) => {
|
|
73
68
|
this.readiness(res);
|
|
74
69
|
});
|
|
75
70
|
}
|
|
76
71
|
liveness(res) {
|
|
77
|
-
res.
|
|
78
|
-
res.write('OK');
|
|
79
|
-
res.end();
|
|
72
|
+
res.status(200).type('text/plain').send('OK');
|
|
80
73
|
}
|
|
81
74
|
readiness(res) {
|
|
82
75
|
if (this.state === 'ready') {
|
|
83
|
-
res.
|
|
84
|
-
res.write('OK');
|
|
76
|
+
res.status(200).type('text/plain').send('OK');
|
|
85
77
|
}
|
|
86
78
|
else {
|
|
87
|
-
res.
|
|
88
|
-
res.write('not OK');
|
|
79
|
+
res.status(500).type('text/plain').send('not OK');
|
|
89
80
|
}
|
|
90
|
-
res.end();
|
|
91
81
|
}
|
|
92
82
|
version(res) {
|
|
93
|
-
res.
|
|
94
|
-
res.write(JSON.stringify({
|
|
83
|
+
res.status(200).type('application/json').send({
|
|
95
84
|
env: process.env.NODE_ENV,
|
|
96
85
|
commit: process.env.COMMIT,
|
|
97
86
|
build: process.env.BUILD_NUMBER,
|
|
98
87
|
version: process.env.VERSION
|
|
99
|
-
})
|
|
100
|
-
res.end();
|
|
88
|
+
});
|
|
101
89
|
}
|
|
102
90
|
}
|
|
103
91
|
//# sourceMappingURL=default.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default.js","sourceRoot":"","sources":["../../lib/containers/default.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"default.js","sourceRoot":"","sources":["../../lib/containers/default.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AACzD,OAAO,EAAE,OAAO,EAAsF,MAAM,SAAS,CAAA;AAErH,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,CAAA;AAI7C,MAAM,OAAgB,eAAe;IAC3B,OAAO,CAAiB;IACxB,KAAK,CAAO;IACZ,MAAM,CAAiB;IAErB,IAAI,CAA0B;IAC9B,iBAAiB;QACzB,OAAO,EAAE,CAAA;IACX,CAAC;IAID;QACE,IAAI,CAAC,KAAK,GAAG,UAAU,CAAA;QAEvB,IAAI,CAAC,mBAAmB,EAAE,CAAA;QAE1B,KAAK,IAAI,CAAC,KAAK,EAAE,CA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CAAE,GAAiB;QACjC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC/C,CAAC;IAEO,SAAS,CAAE,GAAiB;QAClC,IAAI,IAAI,CAAC,KAAK,KAAK,OAAO,EAAE,CAAC;YAC3B,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAC/C,CAAC;aAAM,CAAC;YACN,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QACnD,CAAC;IACH,CAAC;IAEO,OAAO,CAAE,GAAiB;QAChC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC;YAC5C,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ;YACzB,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,MAAM;YAC1B,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,YAAY;YAC/B,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,OAAO;SAC7B,CAAC,CAAA;IACJ,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wisemen/app-container",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "A package for a nest app container in kubernetes",
|
|
5
5
|
"directories": {
|
|
6
6
|
"example": "examples"
|
|
@@ -22,14 +22,17 @@
|
|
|
22
22
|
"release": "pnpx release-it"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"
|
|
25
|
+
"fastify": "5.7.4"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@nestjs/common": "^11.1.
|
|
29
|
-
"@nestjs/core": "^11.1.
|
|
30
|
-
"@nestjs/platform-
|
|
28
|
+
"@nestjs/common": "^11.1.13",
|
|
29
|
+
"@nestjs/core": "^11.1.13",
|
|
30
|
+
"@nestjs/platform-fastify": "^11.1.13",
|
|
31
31
|
"@types/express": "^5.0.6",
|
|
32
|
-
"@types/node": "^25.
|
|
32
|
+
"@types/node": "^25.2.1",
|
|
33
|
+
"@typescript-eslint/eslint-plugin": "^8.54.0",
|
|
34
|
+
"@wisemen/eslint-config-nestjs": "^0.2.8",
|
|
35
|
+
"eslint": "^9.39.2",
|
|
33
36
|
"typescript": "^5.9.3"
|
|
34
37
|
},
|
|
35
38
|
"author": "Joren Vandeweyer",
|