|
|
@@ -7,7 +7,7 @@ querystring = require('querystring')
|
|
|
SystemMessageManager = require("../Features/SystemMessages/SystemMessageManager")
|
|
|
_ = require("underscore")
|
|
|
Modules = require "./Modules"
|
|
|
-url = require "url"
|
|
|
+Url = require "url"
|
|
|
|
|
|
fingerprints = {}
|
|
|
Path = require 'path'
|
|
|
@@ -51,11 +51,8 @@ getFingerprint = (path) ->
|
|
|
|
|
|
logger.log "Finished generating file fingerprints"
|
|
|
|
|
|
-
|
|
|
-staticFilesBase = ""
|
|
|
-if Settings.cdn?.web?.host?
|
|
|
- staticFilesBase = Settings.cdn?.web?.host
|
|
|
-
|
|
|
+cdnAvailable = Settings.cdn?.web?.host?
|
|
|
+darkCdnAvailable = Settings.cdn?.web?.darkHost?
|
|
|
|
|
|
module.exports = (app, webRouter, apiRouter)->
|
|
|
webRouter.use (req, res, next)->
|
|
|
@@ -63,14 +60,24 @@ 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 if darkCdnAvailable and isDark
|
|
|
+ staticFilesBase = Settings.cdn?.web?.darkHost
|
|
|
+ else
|
|
|
+ staticFilesBase = ""
|
|
|
+
|
|
|
res.locals.jsPath = jsPath
|
|
|
- res.locals.fullJsPath = url.resolve(staticFilesBase, jsPath)
|
|
|
+ res.locals.fullJsPath = Url.resolve(staticFilesBase, jsPath)
|
|
|
|
|
|
- imgPath = "/img/"
|
|
|
- cssPath = "/stylesheets/"
|
|
|
|
|
|
res.locals.buildJsPath = (jsFile, opts = {})->
|
|
|
- p = Path.join(jsPath, jsFile)
|
|
|
+ path = Path.join(jsPath, jsFile)
|
|
|
|
|
|
doFingerPrint = opts.fingerprint != false
|
|
|
|
|
|
@@ -78,23 +85,25 @@ module.exports = (app, webRouter, apiRouter)->
|
|
|
opts.qs = {}
|
|
|
|
|
|
if !opts.qs?.fingerprint? and doFingerPrint
|
|
|
- opts.qs.fingerprint = getFingerprint(p)
|
|
|
+ opts.qs.fingerprint = getFingerprint(path)
|
|
|
|
|
|
- p = url.resolve(staticFilesBase, p)
|
|
|
+ if opts.cdn != false
|
|
|
+ path = Url.resolve(staticFilesBase, path)
|
|
|
+
|
|
|
qs = querystring.stringify(opts.qs)
|
|
|
|
|
|
if qs? and qs.length > 0
|
|
|
- p = p + "?" + qs
|
|
|
- return p
|
|
|
+ path = path + "?" + qs
|
|
|
+ return path
|
|
|
|
|
|
|
|
|
res.locals.buildCssPath = (cssFile)->
|
|
|
- p = Path.join(cssPath, cssFile)
|
|
|
- return url.resolve(staticFilesBase, p) + "?fingerprint=" + getFingerprint(p)
|
|
|
+ path = Path.join("/stylesheets/", cssFile)
|
|
|
+ return Url.resolve(staticFilesBase, path) + "?fingerprint=" + getFingerprint(path)
|
|
|
|
|
|
res.locals.buildImgPath = (imgFile)->
|
|
|
- p = Path.join(imgPath, imgFile)
|
|
|
- return url.resolve(staticFilesBase, p)
|
|
|
+ path = Path.join("/img/", imgFile)
|
|
|
+ return Url.resolve(staticFilesBase, path)
|
|
|
|
|
|
next()
|
|
|
|