|
@@ -12,7 +12,6 @@ Modules = require "./Modules"
|
|
|
Url = require "url"
|
|
Url = require "url"
|
|
|
PackageVersions = require "./PackageVersions"
|
|
PackageVersions = require "./PackageVersions"
|
|
|
htmlEncoder = new require("node-html-encoder").Encoder("numerical")
|
|
htmlEncoder = new require("node-html-encoder").Encoder("numerical")
|
|
|
-fingerprints = {}
|
|
|
|
|
hashedFiles = {}
|
|
hashedFiles = {}
|
|
|
Path = require 'path'
|
|
Path = require 'path'
|
|
|
Features = require "./Features"
|
|
Features = require "./Features"
|
|
@@ -31,49 +30,39 @@ getFileContent = (filePath)->
|
|
|
filePath = Path.join __dirname, "../../../", "public#{filePath}"
|
|
filePath = Path.join __dirname, "../../../", "public#{filePath}"
|
|
|
exists = fs.existsSync filePath
|
|
exists = fs.existsSync filePath
|
|
|
if exists
|
|
if exists
|
|
|
- content = fs.readFileSync filePath
|
|
|
|
|
|
|
+ content = fs.readFileSync filePath, "UTF-8"
|
|
|
return content
|
|
return content
|
|
|
else
|
|
else
|
|
|
- logger.log filePath:filePath, "file does not exist for fingerprints"
|
|
|
|
|
|
|
+ logger.log filePath:filePath, "file does not exist for hashing"
|
|
|
return ""
|
|
return ""
|
|
|
|
|
|
|
|
-logger.log "Generating file fingerprints..."
|
|
|
|
|
|
|
+logger.log "Generating file hashes..."
|
|
|
pathList = [
|
|
pathList = [
|
|
|
- ["#{jsPath}libs/require.js"]
|
|
|
|
|
- ["#{jsPath}ide.js"]
|
|
|
|
|
- ["#{jsPath}main.js"]
|
|
|
|
|
- ["#{jsPath}libraries.js"]
|
|
|
|
|
- ["/stylesheets/style.css"]
|
|
|
|
|
- ["/stylesheets/ol-style.css"]
|
|
|
|
|
|
|
+ "#{jsPath}libs/require.js"
|
|
|
|
|
+ "#{jsPath}ide.js"
|
|
|
|
|
+ "#{jsPath}main.js"
|
|
|
|
|
+ "#{jsPath}libraries.js"
|
|
|
|
|
+ "/stylesheets/style.css"
|
|
|
|
|
+ "/stylesheets/ol-style.css"
|
|
|
]
|
|
]
|
|
|
|
|
|
|
|
-for paths in pathList
|
|
|
|
|
- contentList = _.map(paths, getFileContent)
|
|
|
|
|
- content = contentList.join("")
|
|
|
|
|
|
|
+for path in pathList
|
|
|
|
|
+ content = getFileContent(path)
|
|
|
hash = crypto.createHash("md5").update(content).digest("hex")
|
|
hash = crypto.createHash("md5").update(content).digest("hex")
|
|
|
- _.each paths, (filePath)->
|
|
|
|
|
- logger.log "#{filePath}: #{hash}"
|
|
|
|
|
- fingerprints[filePath] = hash
|
|
|
|
|
-
|
|
|
|
|
- for path in paths
|
|
|
|
|
- splitPath = path.split("/")
|
|
|
|
|
- filenameSplit = splitPath.pop().split(".")
|
|
|
|
|
- filenameSplit.splice(filenameSplit.length-1, 0, hash)
|
|
|
|
|
- splitPath.push(filenameSplit.join("."))
|
|
|
|
|
- hashPath = splitPath.join("/")
|
|
|
|
|
- fsHashPath = Path.join __dirname, "../../../", "public#{hashPath}"
|
|
|
|
|
- fs.writeFileSync(fsHashPath, content)
|
|
|
|
|
- hashedFiles[paths] = hashPath
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-getFingerprint = (path) ->
|
|
|
|
|
- if fingerprints[path]?
|
|
|
|
|
- return fingerprints[path]
|
|
|
|
|
- else
|
|
|
|
|
- logger.err "No fingerprint for file: #{path}"
|
|
|
|
|
- return ""
|
|
|
|
|
|
|
+
|
|
|
|
|
+ splitPath = path.split("/")
|
|
|
|
|
+ filenameSplit = splitPath.pop().split(".")
|
|
|
|
|
+ filenameSplit.splice(filenameSplit.length-1, 0, hash)
|
|
|
|
|
+ splitPath.push(filenameSplit.join("."))
|
|
|
|
|
+
|
|
|
|
|
+ hashPath = splitPath.join("/")
|
|
|
|
|
+ hashedFiles[path] = hashPath
|
|
|
|
|
|
|
|
-logger.log "Finished generating file fingerprints"
|
|
|
|
|
|
|
+ fsHashPath = Path.join __dirname, "../../../", "public#{hashPath}"
|
|
|
|
|
+ fs.writeFileSync(fsHashPath, content)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+logger.log "Finished hashing static content"
|
|
|
|
|
|
|
|
cdnAvailable = Settings.cdn?.web?.host?
|
|
cdnAvailable = Settings.cdn?.web?.host?
|
|
|
darkCdnAvailable = Settings.cdn?.web?.darkHost?
|
|
darkCdnAvailable = Settings.cdn?.web?.darkHost?
|
|
@@ -135,14 +124,9 @@ module.exports = (app, webRouter, privateApiRouter, publicApiRouter)->
|
|
|
if opts.hashedPath
|
|
if opts.hashedPath
|
|
|
path = hashedFiles[path]
|
|
path = hashedFiles[path]
|
|
|
|
|
|
|
|
- doFingerPrint = opts.fingerprint != false
|
|
|
|
|
-
|
|
|
|
|
if !opts.qs?
|
|
if !opts.qs?
|
|
|
opts.qs = {}
|
|
opts.qs = {}
|
|
|
|
|
|
|
|
- if !opts.qs?.fingerprint? and doFingerPrint
|
|
|
|
|
- opts.qs.fingerprint = getFingerprint(path)
|
|
|
|
|
-
|
|
|
|
|
if opts.cdn != false
|
|
if opts.cdn != false
|
|
|
path = Url.resolve(staticFilesBase, path)
|
|
path = Url.resolve(staticFilesBase, path)
|
|
|
|
|
|
|
@@ -160,7 +144,7 @@ module.exports = (app, webRouter, privateApiRouter, publicApiRouter)->
|
|
|
if opts?.hashedPath
|
|
if opts?.hashedPath
|
|
|
hashedPath = hashedFiles[path]
|
|
hashedPath = hashedFiles[path]
|
|
|
return Url.resolve(staticFilesBase, hashedPath)
|
|
return Url.resolve(staticFilesBase, hashedPath)
|
|
|
- return Url.resolve(staticFilesBase, path) + "?fingerprint=" + getFingerprint(path)
|
|
|
|
|
|
|
+ return Url.resolve(staticFilesBase, path)
|
|
|
|
|
|
|
|
res.locals.buildImgPath = (imgFile)->
|
|
res.locals.buildImgPath = (imgFile)->
|
|
|
path = Path.join("/img/", imgFile)
|
|
path = Path.join("/img/", imgFile)
|
|
@@ -245,10 +229,6 @@ module.exports = (app, webRouter, privateApiRouter, publicApiRouter)->
|
|
|
return req.query?[field]
|
|
return req.query?[field]
|
|
|
next()
|
|
next()
|
|
|
|
|
|
|
|
- webRouter.use (req, res, next)->
|
|
|
|
|
- res.locals.fingerprint = getFingerprint
|
|
|
|
|
- next()
|
|
|
|
|
-
|
|
|
|
|
webRouter.use (req, res, next)->
|
|
webRouter.use (req, res, next)->
|
|
|
res.locals.formatPrice = SubscriptionFormatters.formatPrice
|
|
res.locals.formatPrice = SubscriptionFormatters.formatPrice
|
|
|
next()
|
|
next()
|