From 0f69ee0f2293a45da4aa3598ba59cb89051832c9 Mon Sep 17 00:00:00 2001 From: James Allen Date: Mon, 9 Mar 2015 14:09:09 +0000 Subject: [PATCH] Add in proxy for /socket.io so that we don't need to faff with real-time service location --- .../RealTimeProxy/RealTimeProxyRouter.coffee | 12 ++++++++++++ services/web/app/coffee/router.coffee | 2 ++ services/web/config/settings.defaults.coffee | 2 ++ services/web/package.json | 1 + 4 files changed, 17 insertions(+) create mode 100644 services/web/app/coffee/Features/RealTimeProxy/RealTimeProxyRouter.coffee diff --git a/services/web/app/coffee/Features/RealTimeProxy/RealTimeProxyRouter.coffee b/services/web/app/coffee/Features/RealTimeProxy/RealTimeProxyRouter.coffee new file mode 100644 index 0000000000..27beb37f0a --- /dev/null +++ b/services/web/app/coffee/Features/RealTimeProxy/RealTimeProxyRouter.coffee @@ -0,0 +1,12 @@ +settings = require "settings-sharelatex" + +httpProxy = require('http-proxy'); +proxy = httpProxy.createProxyServer({ + target: settings.apis.realTime.url + ws: true +}) + +module.exports = + apply: (app) -> + app.all /\/socket\.io\/.*/, (req, res, next) -> + proxy.web req, res, next \ No newline at end of file diff --git a/services/web/app/coffee/router.coffee b/services/web/app/coffee/router.coffee index 8b58d205f6..fe0827f516 100644 --- a/services/web/app/coffee/router.coffee +++ b/services/web/app/coffee/router.coffee @@ -34,6 +34,7 @@ BlogController = require("./Features/Blog/BlogController") WikiController = require("./Features/Wiki/WikiController") Modules = require "./infrastructure/Modules" RateLimiterMiddlewear = require('./Features/Security/RateLimiterMiddlewear') +RealTimeProxyRouter = require('./Features/RealTimeProxy/RealTimeProxyRouter') logger = require("logger-sharelatex") _ = require("underscore") @@ -62,6 +63,7 @@ module.exports = class Router UploadsRouter.apply(app) PasswordResetRouter.apply(app) StaticPagesRouter.apply(app) + RealTimeProxyRouter.apply(app) Modules.applyRouter(app) diff --git a/services/web/config/settings.defaults.coffee b/services/web/config/settings.defaults.coffee index 38ebf6dbac..fe015b8785 100644 --- a/services/web/config/settings.defaults.coffee +++ b/services/web/config/settings.defaults.coffee @@ -100,6 +100,8 @@ module.exports = subdomain: "" geoIpLookup: url: "http://localhost:8080/json" + realTime: + url: "http://localhost:3026" templates: user_id: process.env.TEMPLATES_USER_ID or "5395eb7aad1f29a88756c7f2" diff --git a/services/web/package.json b/services/web/package.json index 337f42390a..ef22f8f57e 100644 --- a/services/web/package.json +++ b/services/web/package.json @@ -18,6 +18,7 @@ "dateformat": "1.0.4-1.2.3", "express": "3.3.4", "fairy": "0.0.2", + "http-proxy": "^1.8.1", "jade": "~1.3.1", "ldapjs": "^0.7.1", "logger-sharelatex": "git+https://github.com/sharelatex/logger-sharelatex.git#v1.0.0",