2019-07-03 12:41:01 +00:00
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* DS103: Rewrite code to no longer use __guard__
|
|
|
|
* DS207: Consider shorter variations of null checks
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2020-11-25 11:57:24 +00:00
|
|
|
const metrics = require('@overleaf/metrics')
|
2019-07-03 12:41:01 +00:00
|
|
|
metrics.initialize('spelling')
|
|
|
|
|
2021-07-12 16:47:20 +00:00
|
|
|
const Settings = require('@overleaf/settings')
|
2021-12-14 13:00:35 +00:00
|
|
|
const logger = require('@overleaf/logger')
|
2019-07-03 12:41:01 +00:00
|
|
|
logger.initialize('spelling')
|
|
|
|
if ((Settings.sentry != null ? Settings.sentry.dsn : undefined) != null) {
|
|
|
|
logger.initializeErrorReporting(Settings.sentry.dsn)
|
|
|
|
}
|
|
|
|
metrics.memory.monitor(logger)
|
|
|
|
|
|
|
|
const SpellingAPIController = require('./app/js/SpellingAPIController')
|
|
|
|
const express = require('express')
|
2020-07-22 08:22:19 +00:00
|
|
|
const app = express()
|
|
|
|
metrics.injectMetricsRoute(app)
|
2019-07-03 12:41:01 +00:00
|
|
|
const bodyParser = require('body-parser')
|
|
|
|
const HealthCheckController = require('./app/js/HealthCheckController')
|
|
|
|
|
2020-07-22 08:22:19 +00:00
|
|
|
app.use(bodyParser.json({ limit: '2mb' }))
|
|
|
|
app.use(metrics.http.monitor(logger))
|
2019-07-03 12:41:01 +00:00
|
|
|
|
2020-07-22 08:22:19 +00:00
|
|
|
app.post('/user/:user_id/check', SpellingAPIController.check)
|
|
|
|
app.get('/status', (req, res) => res.send({ status: 'spelling api is up' }))
|
2019-07-03 12:41:01 +00:00
|
|
|
|
2020-07-22 08:22:19 +00:00
|
|
|
app.get('/health_check', HealthCheckController.healthCheck)
|
2019-07-03 12:41:01 +00:00
|
|
|
|
2019-07-09 18:12:30 +00:00
|
|
|
const settings =
|
|
|
|
Settings.internal && Settings.internal.spelling
|
|
|
|
? Settings.internal.spelling
|
2019-07-03 12:41:01 +00:00
|
|
|
: undefined
|
2019-07-09 18:12:30 +00:00
|
|
|
const host = settings && settings.host ? settings.host : 'localhost'
|
|
|
|
const port = settings && settings.port ? settings.port : 3005
|
|
|
|
|
|
|
|
if (!module.parent) {
|
|
|
|
// application entry point, called directly
|
2022-01-06 10:41:31 +00:00
|
|
|
app.listen(port, host, function (error) {
|
|
|
|
if (error != null) {
|
|
|
|
throw error
|
|
|
|
}
|
2022-05-16 12:38:18 +00:00
|
|
|
return logger.debug(`spelling starting up, listening on ${host}:${port}`)
|
2022-01-06 10:41:31 +00:00
|
|
|
})
|
2019-07-03 12:41:01 +00:00
|
|
|
}
|
2019-07-09 18:12:30 +00:00
|
|
|
|
2020-07-22 08:22:19 +00:00
|
|
|
module.exports = app
|