app.coffee 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. Settings = require 'settings-sharelatex'
  2. logger = require 'logger-sharelatex'
  3. logger.initialize("notifications-sharelatex")
  4. express = require('express')
  5. app = express()
  6. controller = require("./app/js/NotificationsController")
  7. mongojs = require('mongojs')
  8. db = mongojs(Settings.mongo.url, ['notifications'])
  9. Path = require("path")
  10. metrics = require("metrics-sharelatex")
  11. metrics.initialize("notifications")
  12. metrics.memory.monitor(logger)
  13. HealthCheckController = require("./app/js/HealthCheckController")
  14. app.configure ()->
  15. app.use express.methodOverride()
  16. app.use express.bodyParser()
  17. app.use metrics.http.monitor(logger)
  18. app.use express.errorHandler()
  19. app.post '/user/:user_id', controller.addNotification
  20. app.get '/user/:user_id', controller.getUserNotifications
  21. app.del '/user/:user_id/notification/:notification_id', controller.removeNotificationId
  22. app.del '/user/:user_id', controller.removeNotificationKey
  23. app.del '/key/:key', controller.removeNotificationByKeyOnly
  24. app.get '/status', (req, res)->
  25. res.send('notifications sharelatex up')
  26. app.get '/health_check', (req, res)->
  27. HealthCheckController.check (err)->
  28. if err?
  29. logger.err err:err, "error performing health check"
  30. res.send 500
  31. else
  32. res.send 200
  33. app.get '*', (req, res)->
  34. res.send 404
  35. host = Settings.internal?.notifications?.host || "localhost"
  36. port = Settings.internal?.notifications?.port || 3042
  37. app.listen port, host, ->
  38. logger.info "notifications starting up, listening on #{host}:#{port}"