Skip to content

Commit 245046b

Browse files
Merge pull request #414 from nmarklund10/nmarklund10/issue-413/healthv2
Nmarklund10/issue 413/healthv2
2 parents a8155a9 + 99dc444 commit 245046b

File tree

15 files changed

+266
-273
lines changed

15 files changed

+266
-273
lines changed

package-lock.json

Lines changed: 80 additions & 241 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@
7878
"babel-loader": "^8.2.3",
7979
"chakram": "^1.5.0",
8080
"codecov": "3.7.2",
81-
"eslint": "^8.10.0",
82-
"eslint-plugin-mocha": "8.0.0",
81+
"eslint": "^8.12.0",
82+
"eslint-plugin-mocha": "^10.0.3",
8383
"nyc": "15.0.0",
8484
"sequelize-cli": "^6.4.1"
8585
},

src/api-docs/v2/swagger.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"servers": [
44
{
55
"description": "localhost",
6-
"url": "http://localhost:3000"
6+
"url": "http://localhost:3001"
77
}
88
],
99
"info": {
@@ -91,8 +91,7 @@
9191
"security": [],
9292
"tags": [
9393
"operations",
94-
"read-only",
95-
"unimplemented"
94+
"read-only"
9695
],
9796
"summary": "Checks the health of the application; will be renamed to '/health'.",
9897
"description": "The health of individual application components is verified.",

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ app.get('/help', (req, res) => {
5454
// Api Docs
5555
const apiVersions = fs.readdirSync(`${__dirname}/api-docs`)
5656
for (const version of apiVersions) {
57-
const swaggerDocument = require(`./api-docs/${version}/swagger.json`)
5857
app.use(`/${version}/api-docs`, apiLimiter, swaggerUi.serve, (req, res) => {
58+
const swaggerDocument = require(`./api-docs/${version}/swagger.json`)
5959
let html = swaggerUi.generateHTML(swaggerDocument, swaggerOptions)
6060
res.send(html)
6161
})

src/routes/v2/health.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { Router } from 'express'
2+
import utils from '../../utils'
3+
import { sequelize } from '../../models'
4+
5+
const router = new Router()
6+
7+
const checkDatabase = async () => {
8+
const databaseCheckResult = {
9+
'name': 'database',
10+
'status': 'healthy',
11+
'message': 'N/A'
12+
}
13+
try {
14+
// https://sequelize.org/docs/v6/getting-started/#testing-the-connection
15+
await sequelize.authenticate()
16+
}
17+
catch (error) {
18+
console.error(`Database seems to be down: '${error}'`)
19+
databaseCheckResult.status = 'down'
20+
databaseCheckResult.message = error.message
21+
}
22+
return databaseCheckResult
23+
}
24+
25+
router.get('/', async (req, res) => {
26+
res.status(200).json({
27+
uptime: utils.formatTime(process.uptime()),
28+
environment: process.env.NODE_ENV || 'n/a',
29+
version: process.env.npm_package_version || 'n/a',
30+
requestId: req.id,
31+
checks: [
32+
await checkDatabase()
33+
]
34+
})
35+
})
36+
37+
export default router

src/routes/v2/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import health from './health'
2+
// Exports object of routes we import above. Add to this if you're adding new routes.
3+
4+
const routeExports = {
5+
health
6+
}
7+
8+
module.exports = routeExports

src/tests/v1/contact.routes.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const entity = {
2626
type: 'Test'
2727
}
2828

29-
describe('Contact tests', function() {
29+
describe(`Contact tests (v${VERSION})`, function() {
3030
const authed = new Login(VERSION)
3131
let token
3232
let authHeader

src/tests/v1/csv.routes.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Login } from '../../utils/login'
44
import app from '../..'
55

66
const VERSION = '1'
7-
describe('CSV Dump Negative Tests', function() {
7+
describe(`CSV Dump Negative Tests (v${VERSION})`, function() {
88
const authed = new Login(VERSION)
99
let token
1010

src/tests/v1/entity.routes.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const contact = {
2929
]
3030
}
3131

32-
describe('Entity tests', function() {
32+
describe(`Entity tests (v${VERSION})`, function() {
3333
const authed = new Login(VERSION)
3434
let token
3535

src/tests/v1/index.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import app from '../..'
55
const VERSION = '1'
66
const {expect} = chai
77

8-
describe('API Integration Tests', function() {
8+
describe(`API Integration Tests (v${VERSION})`, function() {
99
it('should return uptime', function(done) {
1010
request(app)
1111
.get(`/v${VERSION}/health`)

0 commit comments

Comments
 (0)