overleaf/services/notifications/app.coffee

49 lines
1.5 KiB
CoffeeScript
Raw Normal View History

2019-01-09 10:20:36 -05:00
metrics = require("metrics-sharelatex")
metrics.initialize("notifications")
2016-01-14 07:35:16 -05:00
Settings = require 'settings-sharelatex'
logger = require 'logger-sharelatex'
logger.initialize("notifications-sharelatex")
express = require('express')
app = express()
2016-01-14 15:42:48 -05:00
controller = require("./app/js/NotificationsController")
2016-01-14 07:35:16 -05:00
mongojs = require('mongojs')
db = mongojs(Settings.mongo.url, ['notifications'])
Path = require("path")
2019-01-09 10:20:36 -05:00
2016-01-14 07:35:16 -05:00
metrics.memory.monitor(logger)
HealthCheckController = require("./app/js/HealthCheckController")
app.configure ()->
app.use express.methodOverride()
app.use express.bodyParser()
app.use metrics.http.monitor(logger)
app.use express.errorHandler()
2019-01-09 10:20:36 -05:00
metrics.injectMetricsRoute(app)
2016-01-14 07:35:16 -05:00
app.post '/user/:user_id', controller.addNotification
2016-01-14 15:42:48 -05:00
app.get '/user/:user_id', controller.getUserNotifications
2016-02-05 04:38:32 -05:00
app.del '/user/:user_id/notification/:notification_id', controller.removeNotificationId
app.del '/user/:user_id', controller.removeNotificationKey
app.del '/key/:key', controller.removeNotificationByKeyOnly
2016-01-14 07:35:16 -05:00
app.get '/status', (req, res)->
res.send('notifications sharelatex up')
app.get '/health_check', (req, res)->
HealthCheckController.check (err)->
if err?
logger.err err:err, "error performing health check"
res.send 500
else
res.send 200
app.get '*', (req, res)->
res.send 404
host = Settings.internal?.notifications?.host || "localhost"
2016-02-04 08:46:59 -05:00
port = Settings.internal?.notifications?.port || 3042
2016-01-14 07:35:16 -05:00
app.listen port, host, ->
logger.info "notifications starting up, listening on #{host}:#{port}"