Skip to content

Commit

Permalink
Feature/sqnc 54 (#544)
Browse files Browse the repository at this point in the history
* SQNC-534: addingh express-prom-bundle package along with middleware.

* SQNC-54: rebase and version increase.

* SQNC-54: linting.

* SQNC-54: remove function from promBundle.

* SQNC-54: downgrade prom-bundle to v7.

* SQNC-54: version bump.

* SQNC-54: moving promBundle to the variable.
  • Loading branch information
n3op2 authored Dec 18, 2024
1 parent 33f2944 commit 38dbfea
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
63 changes: 63 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 @@ -83,6 +83,7 @@
"dotenv": "^16.4.7",
"envalid": "^8.0.0",
"express": "^4.21.2",
"express-prom-bundle": "^7.0.0",
"knex": "^3.1.0",
"moment": "^2.30.1",
"multer": "^1.4.5-lts.1",
Expand Down
11 changes: 11 additions & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import express, { Express } from 'express'
import { setup, serve, SwaggerUiOptions } from 'swagger-ui-express'
import cors from 'cors'
import bodyParser from 'body-parser'
import promBundle from 'express-prom-bundle'

import { errorHandler } from './lib/error-handler/index.js'
import { RegisterRoutes } from './routes.js'
Expand All @@ -24,6 +25,14 @@ const customCssToInject: string = `
.swagger-ui section.models { background-color: #f7f7f7; }
`
const promClient = promBundle({
includePath: true,
promClient: {
collectDefaultMetrics: {
prefix: 'sqnc_matchmaker_api_',
},
},
})

export default async (): Promise<Express> => {
const app: Express = express()
Expand All @@ -37,6 +46,8 @@ export default async (): Promise<Express> => {
app.use(bodyParser.urlencoded({ extended: true }))
app.use(bodyParser.json())
app.use(cors())
app.use(promClient)

app.use((req, _, next) => {
// make sure we always have a file object on req even if this is not a multipart
// body this is so that the attachment route can handle both JSON and multipart bodies
Expand Down

0 comments on commit 38dbfea

Please sign in to comment.