From 6aca798a452d2a2e79b6605c5dd2a864fd807b11 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Thu, 21 Jul 2016 15:34:23 +0100 Subject: [PATCH] =?UTF-8?q?don=E2=80=99t=20use=20cdn=20on=20dark?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../infrastructure/ExpressLocals.coffee | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/services/web/app/coffee/infrastructure/ExpressLocals.coffee b/services/web/app/coffee/infrastructure/ExpressLocals.coffee index 240bc5bef7..2206b0fff1 100644 --- a/services/web/app/coffee/infrastructure/ExpressLocals.coffee +++ b/services/web/app/coffee/infrastructure/ExpressLocals.coffee @@ -51,11 +51,7 @@ getFingerprint = (path) -> logger.log "Finished generating file fingerprints" - -staticFilesBase = "" -if Settings.cdn?.web?.host? - staticFilesBase = Settings.cdn?.web?.host - +cdnAvailable = Settings.cdn?.web?.host? module.exports = (app, webRouter, apiRouter)-> webRouter.use (req, res, next)-> @@ -63,11 +59,19 @@ module.exports = (app, webRouter, apiRouter)-> next() webRouter.use (req, res, next)-> + + 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 + staticFilesBase = Settings.cdn?.web?.host + else + staticFilesBase = "" + res.locals.jsPath = jsPath res.locals.fullJsPath = Url.resolve(staticFilesBase, jsPath) - imgPath = "/img/" - cssPath = "/stylesheets/" res.locals.buildJsPath = (jsFile, opts = {})-> path = Path.join(jsPath, jsFile) @@ -89,11 +93,11 @@ module.exports = (app, webRouter, apiRouter)-> res.locals.buildCssPath = (cssFile)-> - path = Path.join(cssPath, cssFile) + path = Path.join("/stylesheets/", cssFile) return Url.resolve(staticFilesBase, path) + "?fingerprint=" + getFingerprint(path) res.locals.buildImgPath = (imgFile)-> - path = Path.join(imgPath, imgFile) + path = Path.join("/img/", imgFile) return Url.resolve(staticFilesBase, path) next()