Merge branch 'master' of github.com:sharelatex/real-time-sharelatex

This commit is contained in:
James Allen 2016-12-08 11:16:22 +00:00
commit 7bade0a8bb
2 changed files with 21 additions and 12 deletions

View file

@ -1,20 +1,28 @@
logger = require "logger-sharelatex"
logger.initialize("real-time-sharelatex")
express = require("express")
session = require("express-session")
redis = require("redis-sharelatex")
ioredis = require('ioredis')
Settings = require "settings-sharelatex"
redisSessionsSettings = Settings.redis.websessions or Settings.redis.web
if redisSessionsSettings?.cluster?
logger.log {}, "using redis cluster for web sessions"
sessionRedisClient = new ioredis.Cluster(redisSessionsSettings.cluster)
else
sessionRedisClient = redis.createClient(redisSessionsSettings)
RedisStore = require('connect-redis')(session)
SessionSockets = require('session.socket.io')
CookieParser = require("cookie-parser")
Settings = require "settings-sharelatex"
logger = require "logger-sharelatex"
logger.initialize("real-time-sharelatex")
Metrics = require("metrics-sharelatex")
Metrics.initialize(Settings.appName or "real-time")
Metrics.event_loop.monitor(logger)
rclient = redis.createClient(Settings.redis.web)
# Set up socket.io server
app = express()
@ -22,7 +30,7 @@ server = require('http').createServer(app)
io = require('socket.io').listen(server)
# Bind to sessions
sessionStore = new RedisStore(client: rclient)
sessionStore = new RedisStore(client: sessionRedisClient)
cookieParser = CookieParser(Settings.security.sessionSecret)
sessionSockets = new SessionSockets(io, sessionStore, cookieParser, Settings.cookieName)
@ -42,14 +50,14 @@ io.configure ->
app.get "/status", (req, res, next) ->
res.send "real-time-sharelatex is alive"
redisCheck = redis.activeHealthCheckRedis(Settings.redis.web)
app.get "/health_check/redis", (req, res, next) ->
if redisCheck.isAlive()
res.send 200
else
res.send 500
Router = require "./app/js/Router"
Router.configure(app, io, sessionSockets)
@ -58,13 +66,13 @@ WebsocketLoadBalancer.listenForEditorEvents(io)
DocumentUpdaterController = require "./app/js/DocumentUpdaterController"
DocumentUpdaterController.listenForUpdatesFromDocumentUpdater(io)
port = Settings.internal.realTime.port
host = Settings.internal.realTime.host
server.listen port, host, (error) ->
throw error if error?
logger.info "realtime starting up, listening on #{host}:#{port}"
# Stop huge stack traces in logs from all the socket.io parsing steps.
Error.stackTraceLimit = 10
Error.stackTraceLimit = 10

View file

@ -15,6 +15,7 @@
"cookie-parser": "^1.3.3",
"express": "^4.10.1",
"express-session": "^1.9.1",
"ioredis": "^2.4.0",
"logger-sharelatex": "git+https://github.com/sharelatex/logger-sharelatex.git#v1.1.0",
"metrics-sharelatex": "git+https://github.com/sharelatex/metrics-sharelatex.git#v1.4.0",
"redis-sharelatex": "0.0.9",