Files
overleaf-cep/services/notifications/app.js
Andrew Rumble 773e5dd856 Convert NotificationsController to TypeScript
GitOrigin-RevId: df1c25e3494fb12c2af74be30a85d8b0d59e1789
2025-09-24 08:05:41 +00:00

57 lines
1.8 KiB
JavaScript

// Metrics must be initialized before importing anything else
import '@overleaf/metrics/initialize.js'
import metrics from '@overleaf/metrics'
import Settings from '@overleaf/settings'
import logger from '@overleaf/logger'
import express from 'express'
import methodOverride from 'method-override'
import { mongoClient } from './app/js/mongodb.js'
import NotificationsController from './app/js/NotificationsController.ts'
import HealthCheckController from './app/js/HealthCheckController.js'
const app = express()
logger.initialize('notifications')
metrics.memory.monitor(logger)
metrics.open_sockets.monitor()
app.use(methodOverride())
app.use(express.json())
app.use(metrics.http.monitor(logger))
metrics.injectMetricsRoute(app)
app.post('/user/:user_id', NotificationsController.addNotification)
app.get('/user/:user_id', NotificationsController.getUserNotifications)
app.delete(
'/user/:user_id/notification/:notification_id',
NotificationsController.removeNotificationId
)
app.delete('/user/:user_id', NotificationsController.removeNotificationKey)
app.delete('/key/:key', NotificationsController.removeNotificationByKeyOnly)
app.get('/key/:key/count', NotificationsController.countNotificationsByKeyOnly)
app.delete(
'/key/:key/bulk',
NotificationsController.deleteUnreadNotificationsByKeyOnlyBulk
)
app.get('/status', (req, res) => res.send('notifications is up'))
app.get('/health_check', HealthCheckController.check)
app.get('*', (req, res) => res.sendStatus(404))
const host = Settings.internal.notifications?.host || '127.0.0.1'
const port = Settings.internal.notifications?.port || 3042
try {
await mongoClient.connect()
} catch (err) {
logger.fatal({ err }, 'Cannot connect to mongo. Exiting.')
process.exit(1)
}
app.listen(port, host, () =>
logger.debug({}, `notifications starting up, listening on ${host}:${port}`)
)