2014-02-12 05:23:40 -05:00
|
|
|
Settings = require('settings-sharelatex')
|
|
|
|
logger = require 'logger-sharelatex'
|
|
|
|
logger.initialize("web-sharelatex")
|
|
|
|
logger.logger.serializers.user = require("./app/js/infrastructure/LoggerSerializers").user
|
|
|
|
logger.logger.serializers.project = require("./app/js/infrastructure/LoggerSerializers").project
|
2014-05-07 10:29:04 -04:00
|
|
|
metrics = require("metrics-sharelatex")
|
|
|
|
metrics.initialize("web")
|
2014-02-12 05:23:40 -05:00
|
|
|
Server = require("./app/js/infrastructure/Server")
|
|
|
|
Errors = require "./app/js/errors"
|
|
|
|
|
|
|
|
argv = require("optimist")
|
|
|
|
.options("user", {alias : "u", description : "Run the server with permissions of the specified user"})
|
|
|
|
.options("group", {alias : "g", description : "Run the server with permissions of the specified group"})
|
|
|
|
.usage("Usage: $0")
|
|
|
|
.argv
|
|
|
|
|
|
|
|
Server.app.use (error, req, res, next) ->
|
2014-04-02 07:44:52 -04:00
|
|
|
logger.error err: error, url:req.url, method:req.method, user:req?.sesson?.user, "error passed to top level next middlewear"
|
2014-02-12 05:23:40 -05:00
|
|
|
res.statusCode = error.status or 500
|
|
|
|
if res.statusCode == 500
|
2015-03-18 12:20:26 -04:00
|
|
|
res.end("Oops, something went wrong with your request, sorry. If this continues, please contact us at #{Settings.adminEmail}")
|
2014-02-12 05:23:40 -05:00
|
|
|
else
|
|
|
|
res.end()
|
|
|
|
|
|
|
|
if Settings.catchErrors
|
|
|
|
# fairy cleans then exits on an uncaughtError, but we don't want
|
|
|
|
# to exit so it doesn't need to do this.
|
|
|
|
require "fairy"
|
|
|
|
process.removeAllListeners "uncaughtException"
|
|
|
|
process.on "uncaughtException", (error) ->
|
|
|
|
logger.error err: error, "uncaughtException"
|
|
|
|
|
|
|
|
port = Settings.port or Settings.internal?.web?.port or 3000
|
2014-09-02 07:00:33 -04:00
|
|
|
host = Settings.internal.web.host or "localhost"
|
|
|
|
Server.server.listen port, host, ->
|
2014-02-12 05:23:40 -05:00
|
|
|
logger.info("web-sharelatex listening on port #{port}")
|
|
|
|
logger.info("#{require('http').globalAgent.maxSockets} sockets enabled")
|
|
|
|
if argv.user
|
|
|
|
process.setuid argv.user
|
|
|
|
logger.info "Running as user: #{argv.user}"
|
|
|
|
if argv.group
|
|
|
|
process.setgid argv.group
|
|
|
|
logger.info "Running as group: #{argv.group}"
|