overleaf/services/web/app/coffee/Features/RealTimeProxy/RealTimeProxyRouter.coffee
Henry Oswald 1cc0cbe8fc split site into 2 routers, webRouter and apiRouter
web router has things like sessions etc added onto it. Api router is minimal, doesn't include things like csrf
2015-07-01 15:23:18 +01:00

21 lines
No EOL
572 B
CoffeeScript

settings = require "settings-sharelatex"
httpProxy = require('http-proxy');
proxy = httpProxy.createProxyServer({
target: settings.apis.realTime.url
})
wsProxy = httpProxy.createProxyServer({
target: settings.apis.realTime.url.replace("http://", "ws://")
ws: true
})
module.exports =
apply: (webRouter, apiRouter) ->
webRouter.all /\/socket\.io\/.*/, (req, res, next) ->
proxy.web req, res, next
setTimeout () ->
Server = require "../../infrastructure/Server"
Server.server.on "upgrade", (req, socket, head) ->
wsProxy.ws req, socket, head
, 0