@apolitical/server 2.5.1 → 2.5.3

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 CHANGED
@@ -5,6 +5,14 @@ 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.3] - 2022-06-29
9
+ ### Changed
10
+ - Pipelines ref
11
+
12
+ ## [2.5.2] - 2022-06-08
13
+ ### Added
14
+ - Probes prefix to support custom path
15
+
8
16
  ## [2.5.1] - 2022-06-01
9
17
  ### Added
10
18
  - Cache to `readinessCheck` and `livenessCheck` checks to avoid overload
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apolitical/server",
3
- "version": "2.5.1",
3
+ "version": "2.5.3",
4
4
  "description": "Node.js module to encapsulate Apolitical's express server setup",
5
5
  "author": "Apolitical Group Limited <engineering@apolitical.co>",
6
6
  "license": "MIT",
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
- return function load(app, { readinessCheck, livenessCheck }) {
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
- // Overwrite checks when defined
10
- if (readinessCheck) {
11
- healthService.registerReadiness(readinessCheck);
12
- }
13
- if (livenessCheck) {
14
- healthService.registerLiveness(livenessCheck);
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
  };