overleaf/services/contacts/app/js/server.js
Alf Eaton c14467b87a Migrate contacts service to ES modules (#10904)
GitOrigin-RevId: c5abb64729530baecbee0eb589eaed39faa2ac56
2022-12-19 09:03:55 +00:00

32 lines
927 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)
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')
}
})