2014-02-12 12:27:43 -05:00
|
|
|
CompileController = require "./app/js/CompileController"
|
|
|
|
Settings = require "settings-sharelatex"
|
|
|
|
logger = require "logger-sharelatex"
|
|
|
|
logger.initialize("clsi")
|
|
|
|
smokeTest = require "smoke-test-sharelatex"
|
|
|
|
|
2014-05-09 09:55:37 -04:00
|
|
|
Metrics = require "metrics-sharelatex"
|
|
|
|
Metrics.initialize("clsi")
|
|
|
|
Metrics.open_sockets.monitor(logger)
|
|
|
|
|
2014-02-12 12:27:43 -05:00
|
|
|
ProjectPersistenceManager = require "./app/js/ProjectPersistenceManager"
|
|
|
|
|
|
|
|
require("./app/js/db").sync()
|
|
|
|
|
|
|
|
express = require "express"
|
2014-05-19 07:18:57 -04:00
|
|
|
bodyParser = require "body-parser"
|
2014-02-12 12:27:43 -05:00
|
|
|
app = express()
|
|
|
|
|
2014-05-09 09:55:37 -04:00
|
|
|
app.use Metrics.http.monitor(logger)
|
|
|
|
|
2014-05-22 07:18:56 -04:00
|
|
|
# Compile requests can take longer than the default two
|
|
|
|
# minutes (including file download time), so bump up the
|
|
|
|
# timeout a bit.
|
|
|
|
TIMEOUT = threeMinutes = 3 * 60 * 1000
|
|
|
|
app.use (req, res, next) ->
|
|
|
|
req.setTimeout TIMEOUT
|
|
|
|
res.setTimeout TIMEOUT
|
|
|
|
next()
|
|
|
|
|
2014-05-19 15:03:05 -04:00
|
|
|
app.post "/project/:project_id/compile", bodyParser.json(limit: "5mb"), CompileController.compile
|
2014-05-19 07:18:57 -04:00
|
|
|
app.delete "/project/:project_id", CompileController.clearCache
|
2014-02-12 12:27:43 -05:00
|
|
|
|
2014-04-08 10:18:56 -04:00
|
|
|
app.get "/project/:project_id/sync/code", CompileController.syncFromCode
|
|
|
|
app.get "/project/:project_id/sync/pdf", CompileController.syncFromPdf
|
|
|
|
|
2014-02-12 12:27:43 -05:00
|
|
|
staticServer = express.static(Settings.path.compilesDir)
|
|
|
|
app.get "/project/:project_id/output/*", (req, res, next) ->
|
|
|
|
req.url = "/#{req.params.project_id}/#{req.params[0]}"
|
|
|
|
staticServer(req, res, next)
|
|
|
|
|
|
|
|
app.get "/status", (req, res, next) ->
|
|
|
|
res.send "CLSI is alive\n"
|
|
|
|
|
|
|
|
app.get "/health_check", smokeTest.run(require.resolve(__dirname + "/test/smoke/js/SmokeTests.js"))
|
|
|
|
|
|
|
|
app.use (error, req, res, next) ->
|
|
|
|
logger.error err: error, "server error"
|
|
|
|
res.send 500
|
|
|
|
|
|
|
|
app.listen port = (Settings.internal?.clsi?.port or 3013), host = (Settings.internal?.clsi?.host or "localhost"), (error) ->
|
|
|
|
logger.log "CLSI listening on #{host}:#{port}"
|
|
|
|
|
|
|
|
setInterval () ->
|
|
|
|
ProjectPersistenceManager.clearExpiredProjects()
|
|
|
|
, tenMinutes = 10 * 60 * 1000
|