From 3d36dc7d6c6cad7e5365a5f944288586f93c6103 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Fri, 19 Aug 2016 11:05:35 +0100 Subject: [PATCH 1/5] mvp for not using cdn when blocked --- .../app/coffee/infrastructure/ExpressLocals.coffee | 9 +++++++-- services/web/app/views/layout.jade | 11 ++++++++++- services/web/config/settings.defaults.coffee | 6 +++--- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/services/web/app/coffee/infrastructure/ExpressLocals.coffee b/services/web/app/coffee/infrastructure/ExpressLocals.coffee index ee7418dacc..155b6ac3c0 100644 --- a/services/web/app/coffee/infrastructure/ExpressLocals.coffee +++ b/services/web/app/coffee/infrastructure/ExpressLocals.coffee @@ -61,11 +61,16 @@ module.exports = (app, webRouter, apiRouter)-> webRouter.use (req, res, next)-> + cdnBlocked = req.query.nocdn == 'true' or req.session.cdnBlocked + + if cdnBlocked and !req.session.cdnBlocked? + req.session.cdnBlocked = true + isDark = req.headers?.host?.slice(0,4)?.toLowerCase() == "dark" isSmoke = req.headers?.host?.slice(0,5)?.toLowerCase() == "smoke" isLive = !isDark and !isSmoke - - if cdnAvailable and isLive + + if cdnAvailable and isLive and !cdnBlocked staticFilesBase = Settings.cdn?.web?.host else if darkCdnAvailable and isDark staticFilesBase = Settings.cdn?.web?.darkHost diff --git a/services/web/app/views/layout.jade b/services/web/app/views/layout.jade index 3c781a4b9f..f1bfeedfee 100644 --- a/services/web/app/views/layout.jade +++ b/services/web/app/views/layout.jade @@ -8,6 +8,7 @@ html(itemscope, itemtype='http://schema.org/Product') window.similarproducts = true style [ng\:cloak], [ng-cloak], [data-ng-cloak], [x-ng-cloak], .ng-cloak, .x-ng-cloak {display: none !important; display: none; } + -if (typeof(gaExperiments) != "undefined") |!{gaExperiments} @@ -51,8 +52,16 @@ html(itemscope, itemtype='http://schema.org/Product') window.csrfToken = "#{csrfToken}"; block scripts - script(src=buildJsPath("libs/jquery-1.11.1.min.js", {fingerprint:false})) script(src=buildJsPath("libs/angular-1.3.15.min.js", {fingerprint:false})) + script(src=buildJsPath("libs/jquery-1.11.1.min.js", {fingerprint:false})) + script(type="text/javascript"). + var noCdnKey = "nocdn=true" + var cdnBlocked = typeof jQuery === 'undefined' + var noCdnAlreadyInUrl = window.location.href.indexOf(noCdnKey) != -1 //prevent loops + if (cdnBlocked && !noCdnAlreadyInUrl) { + window.location.search += '&'+noCdnKey; + } + script. window.sharelatex = { siteUrl: '#{settings.siteUrl}', diff --git a/services/web/config/settings.defaults.coffee b/services/web/config/settings.defaults.coffee index a326c3b07d..56f3ee2b81 100644 --- a/services/web/config/settings.defaults.coffee +++ b/services/web/config/settings.defaults.coffee @@ -114,9 +114,9 @@ module.exports = settings = showSocialButtons: false showComments: false - # cdn: - # web: - # host:"http://cdn.sharelatex.dev:3000" + cdn: + web: + host:"http://nowhere.sharelatex.dev" # darkHost:"http://cdn.sharelatex.dev:3000" # Where your instance of ShareLaTeX can be found publically. Used in emails From d8e7bacec4f82ea46912bf63df010ef19d716304 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Fri, 19 Aug 2016 11:53:40 +0100 Subject: [PATCH 2/5] added logging in --- services/web/app/coffee/infrastructure/ExpressLocals.coffee | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/services/web/app/coffee/infrastructure/ExpressLocals.coffee b/services/web/app/coffee/infrastructure/ExpressLocals.coffee index 155b6ac3c0..60f1b682e5 100644 --- a/services/web/app/coffee/infrastructure/ExpressLocals.coffee +++ b/services/web/app/coffee/infrastructure/ExpressLocals.coffee @@ -64,12 +64,14 @@ module.exports = (app, webRouter, apiRouter)-> cdnBlocked = req.query.nocdn == 'true' or req.session.cdnBlocked if cdnBlocked and !req.session.cdnBlocked? + ip = req.ip || req.socket?.socket?.remoteAddress || req.socket?.remoteAddress + logger.log user_id:req?.session?.user?._id, ip:ip, "cdnBlocked for user, not using it" req.session.cdnBlocked = true isDark = req.headers?.host?.slice(0,4)?.toLowerCase() == "dark" isSmoke = req.headers?.host?.slice(0,5)?.toLowerCase() == "smoke" isLive = !isDark and !isSmoke - + if cdnAvailable and isLive and !cdnBlocked staticFilesBase = Settings.cdn?.web?.host else if darkCdnAvailable and isDark From 6a72c2fce08d2e9ef0602d7c08bc7c7c59556b99 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Tue, 23 Aug 2016 16:46:23 +0100 Subject: [PATCH 3/5] comment settings back out --- services/web/config/settings.defaults.coffee | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/web/config/settings.defaults.coffee b/services/web/config/settings.defaults.coffee index 56f3ee2b81..10fef74a11 100644 --- a/services/web/config/settings.defaults.coffee +++ b/services/web/config/settings.defaults.coffee @@ -114,9 +114,9 @@ module.exports = settings = showSocialButtons: false showComments: false - cdn: - web: - host:"http://nowhere.sharelatex.dev" + # cdn: + # web: + # host:"http://nowhere.sharelatex.dev" # darkHost:"http://cdn.sharelatex.dev:3000" # Where your instance of ShareLaTeX can be found publically. Used in emails From fcc75854449c5e690ae097a44d9efdbe98dc2595 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Tue, 23 Aug 2016 16:58:39 +0100 Subject: [PATCH 4/5] put jquery as first script in head tag --- services/web/app/views/layout.jade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/web/app/views/layout.jade b/services/web/app/views/layout.jade index f1bfeedfee..88fe4187fe 100644 --- a/services/web/app/views/layout.jade +++ b/services/web/app/views/layout.jade @@ -52,7 +52,6 @@ html(itemscope, itemtype='http://schema.org/Product') window.csrfToken = "#{csrfToken}"; block scripts - script(src=buildJsPath("libs/angular-1.3.15.min.js", {fingerprint:false})) script(src=buildJsPath("libs/jquery-1.11.1.min.js", {fingerprint:false})) script(type="text/javascript"). var noCdnKey = "nocdn=true" @@ -61,6 +60,7 @@ html(itemscope, itemtype='http://schema.org/Product') if (cdnBlocked && !noCdnAlreadyInUrl) { window.location.search += '&'+noCdnKey; } + script(src=buildJsPath("libs/angular-1.3.15.min.js", {fingerprint:false})) script. window.sharelatex = { From 934e908697b95969f3c4581992604144429e9f9e Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Tue, 23 Aug 2016 17:00:13 +0100 Subject: [PATCH 5/5] just use plain req.ip for logging --- services/web/app/coffee/infrastructure/ExpressLocals.coffee | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/services/web/app/coffee/infrastructure/ExpressLocals.coffee b/services/web/app/coffee/infrastructure/ExpressLocals.coffee index 60f1b682e5..d3b9d9a24b 100644 --- a/services/web/app/coffee/infrastructure/ExpressLocals.coffee +++ b/services/web/app/coffee/infrastructure/ExpressLocals.coffee @@ -64,8 +64,7 @@ module.exports = (app, webRouter, apiRouter)-> cdnBlocked = req.query.nocdn == 'true' or req.session.cdnBlocked if cdnBlocked and !req.session.cdnBlocked? - ip = req.ip || req.socket?.socket?.remoteAddress || req.socket?.remoteAddress - logger.log user_id:req?.session?.user?._id, ip:ip, "cdnBlocked for user, not using it" + logger.log user_id:req?.session?.user?._id, ip:req?.ip, "cdnBlocked for user, not using it and turning it off for future requets" req.session.cdnBlocked = true isDark = req.headers?.host?.slice(0,4)?.toLowerCase() == "dark"