2014-04-29 06:49:09 -04:00
|
|
|
Settings = require "settings-sharelatex"
|
|
|
|
logger = require "logger-sharelatex"
|
|
|
|
express = require "express"
|
|
|
|
bodyParser = require "body-parser"
|
|
|
|
Errors = require "./app/js/Errors"
|
2014-04-28 11:45:59 -04:00
|
|
|
HttpController = require "./app/js/HttpController"
|
2014-05-06 11:52:58 -04:00
|
|
|
Metrics = require "metrics-sharelatex"
|
|
|
|
Path = require "path"
|
2014-04-29 06:49:09 -04:00
|
|
|
|
2014-05-06 11:52:58 -04:00
|
|
|
Metrics.initialize("docstore")
|
2014-04-29 06:49:09 -04:00
|
|
|
logger.initialize("docstore")
|
2015-06-23 08:55:33 -04:00
|
|
|
Metrics.event_loop?.monitor(logger)
|
2014-04-28 11:45:59 -04:00
|
|
|
|
|
|
|
app = express()
|
|
|
|
|
2014-05-07 05:59:16 -04:00
|
|
|
app.use Metrics.http.monitor(logger)
|
|
|
|
|
2016-09-02 08:33:30 -04:00
|
|
|
app.param 'project_id', (req, res, next, project_id) ->
|
|
|
|
if project_id?.match /^[0-9a-f]{24}$/
|
|
|
|
next()
|
|
|
|
else
|
|
|
|
next new Error("invalid project id")
|
|
|
|
|
|
|
|
app.param 'doc_id', (req, res, next, doc_id) ->
|
|
|
|
if doc_id?.match /^[0-9a-f]{24}$/
|
|
|
|
next()
|
|
|
|
else
|
|
|
|
next new Error("invalid doc id")
|
|
|
|
|
2014-04-30 08:06:12 -04:00
|
|
|
app.get '/project/:project_id/doc', HttpController.getAllDocs
|
2016-12-09 09:37:24 -05:00
|
|
|
app.get '/project/:project_id/ranges', HttpController.getAllRanges
|
2014-04-29 06:49:09 -04:00
|
|
|
app.get '/project/:project_id/doc/:doc_id', HttpController.getDoc
|
2014-05-20 08:04:33 -04:00
|
|
|
app.get '/project/:project_id/doc/:doc_id/raw', HttpController.getRawDoc
|
2015-11-06 07:42:44 -05:00
|
|
|
# Add 16kb overhead for the JSON encoding
|
2015-11-09 10:24:21 -05:00
|
|
|
app.post '/project/:project_id/doc/:doc_id', bodyParser.json(limit: Settings.max_doc_length + 16 * 1024), HttpController.updateDoc
|
2014-04-29 11:36:10 -04:00
|
|
|
app.del '/project/:project_id/doc/:doc_id', HttpController.deleteDoc
|
2014-04-28 11:45:59 -04:00
|
|
|
|
2015-08-13 17:48:45 -04:00
|
|
|
app.post '/project/:project_id/archive', HttpController.archiveAllDocs
|
|
|
|
app.post '/project/:project_id/unarchive', HttpController.unArchiveAllDocs
|
2014-04-28 11:45:59 -04:00
|
|
|
|
2015-10-16 05:13:54 -04:00
|
|
|
app.get "/health_check", HttpController.healthCheck
|
2015-10-15 17:22:20 -04:00
|
|
|
|
2014-04-28 11:45:59 -04:00
|
|
|
app.get '/status', (req, res)->
|
|
|
|
res.send('docstore is alive')
|
|
|
|
|
|
|
|
app.use (error, req, res, next) ->
|
|
|
|
logger.error err: error, "request errored"
|
2014-04-28 12:43:19 -04:00
|
|
|
if error instanceof Errors.NotFoundError
|
|
|
|
res.send 404
|
|
|
|
else
|
|
|
|
res.send(500, "Oops, something went wrong")
|
2014-04-28 11:45:59 -04:00
|
|
|
|
|
|
|
port = Settings.internal.docstore.port
|
|
|
|
host = Settings.internal.docstore.host
|
|
|
|
app.listen port, host, (error) ->
|
|
|
|
throw error if error?
|
2015-04-30 10:04:26 -04:00
|
|
|
logger.info "Docstore starting up, listening on #{host}:#{port}"
|