app.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * decaffeinate suggestions:
  3. * DS102: Remove unnecessary code created because of implicit returns
  4. * DS103: Rewrite code to no longer use __guard__
  5. * DS207: Consider shorter variations of null checks
  6. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  7. */
  8. const metrics = require('@overleaf/metrics')
  9. metrics.initialize('spelling')
  10. const Settings = require('@overleaf/settings')
  11. const logger = require('@overleaf/logger')
  12. logger.initialize('spelling')
  13. if ((Settings.sentry != null ? Settings.sentry.dsn : undefined) != null) {
  14. logger.initializeErrorReporting(Settings.sentry.dsn)
  15. }
  16. metrics.memory.monitor(logger)
  17. const SpellingAPIController = require('./app/js/SpellingAPIController')
  18. const express = require('express')
  19. const app = express()
  20. metrics.injectMetricsRoute(app)
  21. const bodyParser = require('body-parser')
  22. const HealthCheckController = require('./app/js/HealthCheckController')
  23. app.use(bodyParser.json({ limit: '2mb' }))
  24. app.use(metrics.http.monitor(logger))
  25. app.post('/user/:user_id/check', SpellingAPIController.check)
  26. app.get('/status', (req, res) => res.send({ status: 'spelling api is up' }))
  27. app.get('/health_check', HealthCheckController.healthCheck)
  28. const settings =
  29. Settings.internal && Settings.internal.spelling
  30. ? Settings.internal.spelling
  31. : undefined
  32. const host = settings && settings.host ? settings.host : 'localhost'
  33. const port = settings && settings.port ? settings.port : 3005
  34. if (!module.parent) {
  35. // application entry point, called directly
  36. app.listen(port, host, function (error) {
  37. if (error != null) {
  38. throw error
  39. }
  40. return logger.debug(`spelling starting up, listening on ${host}:${port}`)
  41. })
  42. }
  43. module.exports = app