Skip to content
Snippets Groups Projects
Commit a4b5da36 authored by Sigmund, Dominik's avatar Sigmund, Dominik
Browse files

initial commit

parents
No related branches found
No related tags found
No related merge requests found
Pipeline #33222 failed
node_modules/
coverage/
stryker.log
*.DS_Store
# stryker temp files
stryker-tmp/
image: node:latest
cache:
paths:
- node_modules/
- docs/
stages:
- test
- publish
test:
stage: test
before_script:
- npm install -g jest
- npm install
script:
- jest
artifacts:
paths:
- docs/test-report.html
- docs/coverage/lcov.info
audit:
stage: test
script:
- npm audit --audit-level=high
publish:
only:
refs:
- tags
stage: publish
script:
- npm install --production
- npm publish
.gitlab-ci.yml
\ No newline at end of file
.npmrc 0 → 100755
tag-version-prefix=""
strict-ssl=false
@libs:registry=https://gitlab.ard.de/api/v4/projects/2921/packages/npm/
//gitlab.ard.de/api/v4/packages/npm/:_authToken=${CI_JOB_TOKEN}
//gitlab.ard.de/api/v4/projects/2921/packages/npm/:_authToken=${CI_JOB_TOKEN}
# MetaRoutes
Add default metaroutes to express app
## Installation
- `npm install --save @libs/metaroutes`
## Usage
`const metaRoutes = require('@libs/metaRoutes');`
`metaRoutes(app, { version, config, isServiceReady, metricsEndpoint }, routeOptions);`
Where:
- `app` is the express app
- `version` is the version of the service as a string
- `config` is the config object of @libs/config
- `isServiceReady` is a function that returns a boolean indicating if the service is ready
- `metricsEndpoint` is the endpoint for the metrics route from @libs/metrics
- `routeOptions` is an object with the following properties:
- `enableVersion` (default: true) - if true, the version route will be enabled
- `enableHealth` (default: true) - if true, the health route will be enabled
- `enableReady` (default: true) - if true, the ready route will be enabled
- `enableConfig` (default: true) - if true, the config route will be enabled
- `enableMetrics` (default: true) - if true, the metrics route will be enabled
index.js 0 → 100644
// metaRoutes.js
function metaRoutes(app, { version, config, isServiceReady, metricsEndpoint }, routeOptions = {}) {
// Default options with all routes enabled
const defaults = {
enableVersion: true,
enableConfig: true,
enableHealth: true,
enableReady: true,
enableMetrics: true,
};
// Merge user provided options with defaults
const options = { ...defaults, ...routeOptions };
if (options.enableVersion) {
app.get('/_version', function (req, res) {
res.send(version);
});
}
if (options.enableConfig) {
app.get('/_config', function (req, res) {
res.send(config._show());
});
}
if (options.enableHealth) {
app.get('/_health', function (req, res) {
res.send('OK');
});
}
if (options.enableReady) {
app.get('/_ready', function (req, res) {
if (isServiceReady()) {
res.send('OK');
} else {
res.status(503).send('Not ready');
}
});
}
if (options.enableMetrics) {
app.get('/_metrics', metricsEndpoint);
}
}
module.exports = metaRoutes;
{
"name": "@libs/metaroutes",
"version": "1.0.0",
"description": "Add default metaroutes to express app",
"main": "index.ts",
"scripts": {
"test": "jest",
"test:mutation": "stryker run"
},
"keywords": [
"routes",
"meta",
"express",
"api"
],
"author": "Dominik Sigmund <dominik.sigmund@br.de>",
"license": "ISC",
"dependencies": {
"lodash.merge": "^4.6.2"
},
"devDependencies": {
"@stryker-mutator/core": "^7.1.0",
"@stryker-mutator/javascript-mutator": "^4.0.0",
"@stryker-mutator/jest-runner": "^7.1.0",
"@stryker-mutator/typescript": "^4.0.0",
"jest": "^29.5.0"
},
"publishConfig": {
"@libs:registry": "https://gitlab.ard.de/api/v4/projects/2921/packages/npm/"
},
"jest": {
"collectCoverage": true,
"coverageReporters": [
"json",
"lcov",
"text",
"clover",
"html"
],
"coverageDirectory": "docs/coverage"
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment