Merge pull request #305 from sharelatex/cdnfallback

don't use cdn if it can not be accessed
This commit is contained in:
Henry Oswald 2016-08-24 09:45:14 +01:00 committed by GitHub
commit 3f4e888af5
3 changed files with 17 additions and 2 deletions

View file

@ -61,11 +61,17 @@ module.exports = (app, webRouter, apiRouter)->
webRouter.use (req, res, next)-> webRouter.use (req, res, next)->
cdnBlocked = req.query.nocdn == 'true' or req.session.cdnBlocked
if cdnBlocked and !req.session.cdnBlocked?
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" isDark = req.headers?.host?.slice(0,4)?.toLowerCase() == "dark"
isSmoke = req.headers?.host?.slice(0,5)?.toLowerCase() == "smoke" isSmoke = req.headers?.host?.slice(0,5)?.toLowerCase() == "smoke"
isLive = !isDark and !isSmoke isLive = !isDark and !isSmoke
if cdnAvailable and isLive if cdnAvailable and isLive and !cdnBlocked
staticFilesBase = Settings.cdn?.web?.host staticFilesBase = Settings.cdn?.web?.host
else if darkCdnAvailable and isDark else if darkCdnAvailable and isDark
staticFilesBase = Settings.cdn?.web?.darkHost staticFilesBase = Settings.cdn?.web?.darkHost

View file

@ -8,6 +8,7 @@ html(itemscope, itemtype='http://schema.org/Product')
window.similarproducts = true window.similarproducts = true
style [ng\:cloak], [ng-cloak], [data-ng-cloak], [x-ng-cloak], .ng-cloak, .x-ng-cloak {display: none !important; display: none; } 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") -if (typeof(gaExperiments) != "undefined")
|!{gaExperiments} |!{gaExperiments}
@ -52,7 +53,15 @@ html(itemscope, itemtype='http://schema.org/Product')
block scripts block scripts
script(src=buildJsPath("libs/jquery-1.11.1.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(src=buildJsPath("libs/angular-1.3.15.min.js", {fingerprint:false})) script(src=buildJsPath("libs/angular-1.3.15.min.js", {fingerprint:false}))
script. script.
window.sharelatex = { window.sharelatex = {
siteUrl: '#{settings.siteUrl}', siteUrl: '#{settings.siteUrl}',

View file

@ -116,7 +116,7 @@ module.exports = settings =
# cdn: # cdn:
# web: # web:
# host:"http://cdn.sharelatex.dev:3000" # host:"http://nowhere.sharelatex.dev"
# darkHost:"http://cdn.sharelatex.dev:3000" # darkHost:"http://cdn.sharelatex.dev:3000"
# Where your instance of ShareLaTeX can be found publically. Used in emails # Where your instance of ShareLaTeX can be found publically. Used in emails