overleaf/services/spelling/app.coffee

48 lines
1.5 KiB
CoffeeScript
Raw Normal View History

2019-01-03 05:03:49 -05:00
metrics = require("metrics-sharelatex")
metrics.initialize("spelling")
2014-08-15 07:13:35 -04:00
Settings = require 'settings-sharelatex'
logger = require 'logger-sharelatex'
logger.initialize("spelling")
2016-03-23 09:47:28 -04:00
if Settings.sentry?.dsn?
logger.initializeErrorReporting(Settings.sentry.dsn)
2019-01-03 05:03:49 -05:00
metrics.memory.monitor(logger)
2016-03-23 09:47:28 -04:00
2014-08-15 07:13:35 -04:00
SpellingAPIController = require './app/js/SpellingAPIController'
express = require('express')
2014-08-15 07:13:35 -04:00
Path = require("path")
server = express()
2019-01-03 05:03:49 -05:00
metrics.injectMetricsRoute(server)
bodyParser = require('body-parser')
2015-03-01 07:45:14 -05:00
HealthCheckController = require("./app/js/HealthCheckController")
2014-08-15 07:13:35 -04:00
2015-03-03 08:57:05 -05:00
server.use bodyParser.json(limit: "2mb")
2014-08-15 07:13:35 -04:00
server.use metrics.http.monitor(logger)
2017-10-30 12:57:34 -04:00
server.del "/user/:user_id", SpellingAPIController.deleteDic
2019-01-02 09:46:44 -05:00
server.get "/user/:user_id", SpellingAPIController.getDic
2014-08-15 07:13:35 -04:00
server.post "/user/:user_id/check", SpellingAPIController.check
server.post "/user/:user_id/learn", SpellingAPIController.learn
server.get "/status", (req, res)->
res.send(status:'spelling api is up')
2015-03-01 07:45:14 -05:00
server.get "/health_check", HealthCheckController.healthCheck
2015-03-02 10:48:27 -05:00
profiler = require "v8-profiler"
server.get "/profile", (req, res) ->
time = parseInt(req.query.time || "1000")
profiler.startProfiling("test")
setTimeout () ->
profile = profiler.stopProfiling("test")
res.json(profile)
, time
2015-03-01 07:45:14 -05:00
2014-08-15 07:25:54 -04:00
host = Settings.internal?.spelling?.host || "localhost"
port = Settings.internal?.spelling?.port || 3005
server.listen port, host, (error) ->
throw error if error?
2015-04-30 10:05:49 -04:00
logger.info "spelling starting up, listening on #{host}:#{port}"