2014-01-27 17:51:09 +00:00
|
|
|
Settings = require "settings-sharelatex"
|
2013-08-23 13:35:13 +00:00
|
|
|
logger = require "logger-sharelatex"
|
2014-02-26 16:17:15 +00:00
|
|
|
logger.initialize("track-changes")
|
2013-08-23 13:35:13 +00:00
|
|
|
|
2015-12-07 15:52:21 +00:00
|
|
|
if Settings.sentry?.dsn?
|
2015-12-08 10:44:26 +00:00
|
|
|
logger.initializeErrorReporting(Settings.sentry.dsn)
|
2015-12-07 15:52:21 +00:00
|
|
|
|
2014-05-09 11:44:13 +00:00
|
|
|
Path = require "path"
|
|
|
|
Metrics = require "metrics-sharelatex"
|
|
|
|
Metrics.initialize("track-changes")
|
|
|
|
Metrics.mongodb.monitor(Path.resolve(__dirname + "/node_modules/mongojs/node_modules/mongodb"), logger)
|
2016-01-14 16:24:13 +00:00
|
|
|
Metrics.memory.monitor(logger)
|
2014-05-09 11:44:13 +00:00
|
|
|
|
2015-06-04 15:24:35 +00:00
|
|
|
child_process = require "child_process"
|
|
|
|
|
2014-01-27 18:09:37 +00:00
|
|
|
HttpController = require "./app/js/HttpController"
|
|
|
|
express = require "express"
|
|
|
|
app = express()
|
|
|
|
|
2014-05-09 11:44:13 +00:00
|
|
|
app.use Metrics.http.monitor(logger)
|
2014-02-26 12:11:45 +00:00
|
|
|
|
2014-03-21 15:57:17 +00:00
|
|
|
app.post "/project/:project_id/doc/:doc_id/flush", HttpController.flushDoc
|
2013-08-23 13:35:13 +00:00
|
|
|
|
2014-03-04 15:27:03 +00:00
|
|
|
app.get "/project/:project_id/doc/:doc_id/diff", HttpController.getDiff
|
|
|
|
|
2015-12-09 14:57:04 +00:00
|
|
|
app.get "/project/:project_id/doc/:doc_id/check", HttpController.checkDoc
|
|
|
|
|
2014-03-20 12:10:04 +00:00
|
|
|
app.get "/project/:project_id/updates", HttpController.getUpdates
|
2014-03-05 15:59:40 +00:00
|
|
|
|
2014-03-21 15:57:17 +00:00
|
|
|
app.post "/project/:project_id/flush", HttpController.flushProject
|
|
|
|
|
2014-03-10 16:58:26 +00:00
|
|
|
app.post "/project/:project_id/doc/:doc_id/version/:version/restore", HttpController.restore
|
|
|
|
|
2015-06-04 15:23:49 +00:00
|
|
|
app.post "/doc/:doc_id/pack", HttpController.packDoc
|
|
|
|
|
2015-10-01 14:55:07 +00:00
|
|
|
app.post '/project/:project_id/archive', HttpController.archiveProject
|
|
|
|
app.post '/project/:project_id/unarchive', HttpController.unArchiveProject
|
2015-08-06 14:11:43 +00:00
|
|
|
|
2015-06-04 15:24:35 +00:00
|
|
|
packWorker = null # use a single packing worker
|
|
|
|
|
|
|
|
app.post "/pack", (req, res, next) ->
|
|
|
|
if packWorker?
|
|
|
|
res.send "pack already running"
|
|
|
|
else
|
|
|
|
logger.log "running pack"
|
2015-06-05 12:38:47 +00:00
|
|
|
packWorker = child_process.fork(__dirname + '/app/js/PackWorker.js',
|
|
|
|
[req.query.limit, req.query.delay, req.query.timeout])
|
2015-06-04 15:24:35 +00:00
|
|
|
packWorker.on 'exit', (code, signal) ->
|
|
|
|
logger.log {code, signal}, "history auto pack exited"
|
|
|
|
packWorker = null
|
|
|
|
res.send "pack started"
|
|
|
|
|
2014-03-03 13:14:01 +00:00
|
|
|
app.get "/status", (req, res, next) ->
|
|
|
|
res.send "track-changes is alive"
|
|
|
|
|
2015-12-07 16:17:17 +00:00
|
|
|
app.get "/oops", (req, res, next) ->
|
|
|
|
throw new Error("dummy test error")
|
|
|
|
|
2015-10-29 10:52:23 +00:00
|
|
|
app.get "/check_lock", HttpController.checkLock
|
|
|
|
|
2015-10-19 09:59:39 +00:00
|
|
|
app.get "/health_check", HttpController.healthCheck
|
|
|
|
|
2013-08-23 13:35:13 +00:00
|
|
|
app.use (error, req, res, next) ->
|
2016-01-05 15:41:06 +00:00
|
|
|
logger.error err: error, req: req, "an internal error occured"
|
2014-02-26 12:11:45 +00:00
|
|
|
res.send 500
|
2013-08-23 13:35:13 +00:00
|
|
|
|
2014-03-03 13:31:10 +00:00
|
|
|
port = Settings.internal?.trackchanges?.port or 3015
|
2014-02-26 16:17:15 +00:00
|
|
|
host = Settings.internal?.trackchanges?.host or "localhost"
|
2014-02-26 11:34:56 +00:00
|
|
|
app.listen port, host, (error) ->
|
2014-01-27 17:51:09 +00:00
|
|
|
if error?
|
2014-02-26 16:17:15 +00:00
|
|
|
logger.error err: error, "could not start track-changes server"
|
2014-02-26 11:34:56 +00:00
|
|
|
else
|
2015-04-30 14:07:03 +00:00
|
|
|
logger.info "trackchanges starting up, listening on #{host}:#{port}"
|
2014-01-27 17:51:09 +00:00
|
|
|
|