Skip to content

Commit

Permalink
feat: add actuator endpoints to expose health/metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
jrassa committed Feb 2, 2024
1 parent e48daf4 commit f787117
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 0 deletions.
7 changes: 7 additions & 0 deletions config/env/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,13 @@ module.exports = {
path: '/api-docs'
},

actuator: {
enabled: true,
options: {
basePath: '/actuator'
}
},

// The port to use for the application (defaults to the environment variable if present)
port: process.env.PORT || 3001,

Expand Down
73 changes: 73 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"cors": "^2.8.5",
"csv-stringify": "4.0",
"express": "4.17",
"express-actuator": "^1.8.4",
"express-async-errors": "^3.1.1",
"express-json-validator-middleware": "^2.2.1",
"express-session": "1.15",
Expand Down
14 changes: 14 additions & 0 deletions src/lib/express.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import express, { Express, Request, Response } from 'express';
// Patches express to support async/await. Should be called immediately after express.
// Must still use require vs. import
require('express-async-errors');
import actuator from 'express-actuator';
import session from 'express-session';
import helmet from 'helmet';
import _ from 'lodash';
Expand Down Expand Up @@ -205,12 +206,22 @@ function initErrorRoutes(app: Express) {
});
}

function initActuator(app: Express) {
if (!config.actuator.enabled) {
return;
}
logger.info('Configuring actuator endpoints');
app.use(actuator(config.actuator.options));
}

function initSwaggerAPI(app: Express) {
if (!config.apiDocs || config.apiDocs.enabled !== true) {
// apiDocs must be enabled explicitly in the config
return;
}

logger.info('Configuring api docs');

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const swaggerOptions: any = {
swaggerDefinition: {
Expand Down Expand Up @@ -315,6 +326,9 @@ export const init = async (db: Mongoose): Promise<Express> => {
// Initialize Swagger API
initSwaggerAPI(app);

// Initialize Actuator routes
initActuator(app);

// Initialize error routes
initErrorRoutes(app);

Expand Down

0 comments on commit f787117

Please sign in to comment.