From 8f6dac77d02ceac2fe97ca840df3ffaf5771074a Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Tue, 1 Jul 2014 16:00:42 +0100 Subject: [PATCH] added asset proxying from templates in, used for old images etc which people linked to --- .../app/coffee/infrastructure/OldAssetProxy.coffee | 13 +++++++++++++ .../web/app/coffee/infrastructure/Server.coffee | 2 ++ services/web/config/settings.defaults.coffee | 2 ++ 3 files changed, 17 insertions(+) create mode 100644 services/web/app/coffee/infrastructure/OldAssetProxy.coffee diff --git a/services/web/app/coffee/infrastructure/OldAssetProxy.coffee b/services/web/app/coffee/infrastructure/OldAssetProxy.coffee new file mode 100644 index 0000000000..1407d46eca --- /dev/null +++ b/services/web/app/coffee/infrastructure/OldAssetProxy.coffee @@ -0,0 +1,13 @@ +settings = require("settings-sharelatex") +logger = require("logger-sharelatex") +request = require("request") + +module.exports = (req, res, next)-> + requestedUrl = req.url + + redirectUrl = settings.proxyUrls[requestedUrl] + if redirectUrl? + logger.log redirectUrl:redirectUrl, reqUrl:req.url, "proxying url" + request(redirectUrl).pipe(res) + else + next() diff --git a/services/web/app/coffee/infrastructure/Server.coffee b/services/web/app/coffee/infrastructure/Server.coffee index 5eebdf9599..c5e131c9cf 100644 --- a/services/web/app/coffee/infrastructure/Server.coffee +++ b/services/web/app/coffee/infrastructure/Server.coffee @@ -17,6 +17,7 @@ cookieParser = express.cookieParser(Settings.security.sessionSecret) oneDayInMilliseconds = 86400000 ReferalConnect = require('../Features/Referal/ReferalConnect') RedirectManager = require("./RedirectManager") +OldAssetProxy = require("./OldAssetProxy") metrics.mongodb.monitor(Path.resolve(__dirname + "/../../../node_modules/mongojs/node_modules/mongodb"), logger) metrics.mongodb.monitor(Path.resolve(__dirname + "/../../../node_modules/mongoose/node_modules/mongodb"), logger) @@ -76,6 +77,7 @@ app.configure 'production', -> app.use metrics.http.monitor(logger) app.use RedirectManager +app.use OldAssetProxy app.use (req, res, next)-> metrics.inc "http-request" diff --git a/services/web/config/settings.defaults.coffee b/services/web/config/settings.defaults.coffee index 3c8f7f3882..6e674a7711 100644 --- a/services/web/config/settings.defaults.coffee +++ b/services/web/config/settings.defaults.coffee @@ -269,3 +269,5 @@ module.exports = redirects: "/templates/index": "/templates/" + proxyUrls: {} +