mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
5638f06b3a
[metrics] collect HTTP socket stats for all the services GitOrigin-RevId: 52872f4ca46d8cf351f7f4b4df90f9d6b05010b3
33 lines
958 B
JavaScript
33 lines
958 B
JavaScript
import * as Metrics from '@overleaf/metrics'
|
|
import logger from '@overleaf/logger'
|
|
import express from 'express'
|
|
import bodyParser from 'body-parser'
|
|
import * as HttpController from './HttpController.js'
|
|
import * as Errors from './Errors.js'
|
|
|
|
Metrics.initialize('contacts')
|
|
logger.initialize('contacts')
|
|
Metrics.event_loop?.monitor(logger)
|
|
Metrics.open_sockets.monitor()
|
|
|
|
export const app = express()
|
|
app.use(Metrics.http.monitor(logger))
|
|
Metrics.injectMetricsRoute(app)
|
|
|
|
app.get('/user/:user_id/contacts', HttpController.getContacts)
|
|
app.post(
|
|
'/user/:user_id/contacts',
|
|
bodyParser.json({ limit: '2mb' }),
|
|
HttpController.addContact
|
|
)
|
|
|
|
app.get('/status', (req, res) => res.send('contacts is alive'))
|
|
|
|
app.use(function (error, req, res, next) {
|
|
logger.error({ err: error }, 'request errored')
|
|
if (error instanceof Errors.NotFoundError) {
|
|
return res.sendStatus(404)
|
|
} else {
|
|
return res.status(500).send('Oops, something went wrong')
|
|
}
|
|
})
|