@apolitical/server 2.5.1 → 2.5.2-rc.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.
- package/CHANGELOG.md +4 -0
- package/package.json +1 -1
- package/src/config.js +10 -0
- package/src/loaders/probes.loader.js +31 -11
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [2.5.2] - 2022-06-08
|
|
9
|
+
### Added
|
|
10
|
+
- Probes prefix to support custom path
|
|
11
|
+
|
|
8
12
|
## [2.5.1] - 2022-06-01
|
|
9
13
|
### Added
|
|
10
14
|
- Cache to `readinessCheck` and `livenessCheck` checks to avoid overload
|
package/package.json
CHANGED
package/src/config.js
CHANGED
|
@@ -53,6 +53,16 @@ module.exports = {
|
|
|
53
53
|
max: 2, // Only liveness and readiness
|
|
54
54
|
ttl: 60 * 1000, // One minute
|
|
55
55
|
},
|
|
56
|
+
PROBES_OPTIONS: {
|
|
57
|
+
API: {
|
|
58
|
+
ALLOWED_PREFIXES: ['api'],
|
|
59
|
+
PREFIX_PATH: '/api',
|
|
60
|
+
},
|
|
61
|
+
UI: {
|
|
62
|
+
ALLOWED_PREFIXES: ['ui', 'pages'],
|
|
63
|
+
PREFIX_PATH: '/ui',
|
|
64
|
+
},
|
|
65
|
+
},
|
|
56
66
|
},
|
|
57
67
|
JWT: {
|
|
58
68
|
APOLITICAL: {
|
|
@@ -2,21 +2,41 @@
|
|
|
2
2
|
|
|
3
3
|
module.exports = ({ config, logger, healthService }) => {
|
|
4
4
|
const { HEALTH, LIVENESS, READINESS } = config.ENDPOINTS.PROBES;
|
|
5
|
+
const { API, UI } = config.SERVER.PROBES_OPTIONS;
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
function buildPrefix({ prefix }) {
|
|
8
|
+
let result = '';
|
|
9
|
+
if (prefix) {
|
|
10
|
+
if (API.ALLOWED_PREFIXES.some((allowedPrefix) => prefix.includes(allowedPrefix))) {
|
|
11
|
+
result = `${API.PREFIX_PATH}/${prefix}`;
|
|
12
|
+
} else if (UI.ALLOWED_PREFIXES.some((allowedPrefix) => prefix.includes(allowedPrefix))) {
|
|
13
|
+
result = `${UI.PREFIX_PATH}/${prefix}`;
|
|
14
|
+
} else {
|
|
15
|
+
result = prefix;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return result;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return function load(app, { probes }) {
|
|
7
22
|
const childLogger = logger.where(__filename, 'load');
|
|
8
23
|
childLogger.debug('Started');
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
24
|
+
if (probes) {
|
|
25
|
+
const { readinessCheck, livenessCheck } = probes;
|
|
26
|
+
// Overwrite checks when defined
|
|
27
|
+
if (readinessCheck) {
|
|
28
|
+
healthService.registerReadiness(readinessCheck);
|
|
29
|
+
}
|
|
30
|
+
if (livenessCheck) {
|
|
31
|
+
healthService.registerLiveness(livenessCheck);
|
|
32
|
+
}
|
|
33
|
+
// Build base URL
|
|
34
|
+
const probesPath = buildPrefix(probes);
|
|
35
|
+
// Load probes endpoints
|
|
36
|
+
app.get(`${probesPath}${HEALTH}`, healthService.healthEndpoint());
|
|
37
|
+
app.get(`${probesPath}${READINESS}`, healthService.readinessEndpoint());
|
|
38
|
+
app.get(`${probesPath}${LIVENESS}`, healthService.livenessEndpoint());
|
|
15
39
|
}
|
|
16
|
-
// Load probes endpoints
|
|
17
|
-
app.get(HEALTH, healthService.healthEndpoint());
|
|
18
|
-
app.get(READINESS, healthService.readinessEndpoint());
|
|
19
|
-
app.get(LIVENESS, healthService.livenessEndpoint());
|
|
20
40
|
childLogger.debug('Finished');
|
|
21
41
|
};
|
|
22
42
|
};
|