|
|
@@ -7,15 +7,19 @@ querystring = require('querystring')
|
|
|
SystemMessageManager = require("../Features/SystemMessages/SystemMessageManager")
|
|
|
_ = require("underscore")
|
|
|
Modules = require "./Modules"
|
|
|
+Url = require "url"
|
|
|
|
|
|
fingerprints = {}
|
|
|
Path = require 'path'
|
|
|
+
|
|
|
+
|
|
|
jsPath =
|
|
|
if Settings.useMinifiedJs
|
|
|
"/minjs/"
|
|
|
else
|
|
|
"/js/"
|
|
|
|
|
|
+
|
|
|
logger.log "Generating file fingerprints..."
|
|
|
for path in [
|
|
|
"#{jsPath}libs/require.js",
|
|
|
@@ -37,7 +41,21 @@ for path in [
|
|
|
fingerprints[path] = hash
|
|
|
else
|
|
|
logger.log filePath:filePath, "file does not exist for fingerprints"
|
|
|
-
|
|
|
+
|
|
|
+getFingerprint = (path) ->
|
|
|
+ if fingerprints[path]?
|
|
|
+ return fingerprints[path]
|
|
|
+ else
|
|
|
+ logger.err "No fingerprint for file: #{path}"
|
|
|
+ return ""
|
|
|
+
|
|
|
+logger.log "Finished generating file fingerprints"
|
|
|
+
|
|
|
+
|
|
|
+staticFilesBase = ""
|
|
|
+if Settings.cdn?.web?.host?
|
|
|
+ staticFilesBase = Settings.cdn?.web?.host
|
|
|
+
|
|
|
|
|
|
module.exports = (app, webRouter, apiRouter)->
|
|
|
webRouter.use (req, res, next)->
|
|
|
@@ -46,8 +64,42 @@ module.exports = (app, webRouter, apiRouter)->
|
|
|
|
|
|
webRouter.use (req, res, next)->
|
|
|
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)
|
|
|
+
|
|
|
+ doFingerPrint = opts.fingerprint != false
|
|
|
+
|
|
|
+ if !opts.qs?
|
|
|
+ opts.qs = {}
|
|
|
+
|
|
|
+ if !opts.qs?.fingerprint? and doFingerPrint
|
|
|
+ opts.qs.fingerprint = getFingerprint(path)
|
|
|
+
|
|
|
+ path = Url.resolve(staticFilesBase, path)
|
|
|
+ qs = querystring.stringify(opts.qs)
|
|
|
+
|
|
|
+ if qs? and qs.length > 0
|
|
|
+ path = path + "?" + qs
|
|
|
+ return path
|
|
|
+
|
|
|
+
|
|
|
+ res.locals.buildCssPath = (cssFile)->
|
|
|
+ path = Path.join(cssPath, cssFile)
|
|
|
+ return Url.resolve(staticFilesBase, path) + "?fingerprint=" + getFingerprint(path)
|
|
|
+
|
|
|
+ res.locals.buildImgPath = (imgFile)->
|
|
|
+ path = Path.join(imgPath, imgFile)
|
|
|
+ return Url.resolve(staticFilesBase, path)
|
|
|
+
|
|
|
next()
|
|
|
|
|
|
+
|
|
|
+
|
|
|
webRouter.use (req, res, next)->
|
|
|
res.locals.settings = Settings
|
|
|
next()
|
|
|
@@ -113,12 +165,7 @@ module.exports = (app, webRouter, apiRouter)->
|
|
|
next()
|
|
|
|
|
|
webRouter.use (req, res, next)->
|
|
|
- res.locals.fingerprint = (path) ->
|
|
|
- if fingerprints[path]?
|
|
|
- return fingerprints[path]
|
|
|
- else
|
|
|
- logger.err "No fingerprint for file: #{path}"
|
|
|
- return ""
|
|
|
+ res.locals.fingerprint = getFingerprint
|
|
|
next()
|
|
|
|
|
|
webRouter.use (req, res, next)->
|