From c21549220c96979a04786cffbce809288f584736 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Mon, 18 Jul 2016 14:05:07 +0100 Subject: [PATCH 1/6] mvp for cdn --- .../app/coffee/infrastructure/ExpressLocals.coffee | 11 +++++++++++ services/web/app/views/general/500.jade | 4 ++-- services/web/app/views/layout.jade | 2 +- services/web/app/views/project/list/side-bar.jade | 4 ++-- .../views/subscriptions/successful_subscription.jade | 4 ++-- .../app/views/translations/translation_message.jade | 2 +- services/web/config/settings.defaults.coffee | 4 ++++ 7 files changed, 23 insertions(+), 8 deletions(-) diff --git a/services/web/app/coffee/infrastructure/ExpressLocals.coffee b/services/web/app/coffee/infrastructure/ExpressLocals.coffee index faba1e4623..ce5bf50b87 100644 --- a/services/web/app/coffee/infrastructure/ExpressLocals.coffee +++ b/services/web/app/coffee/infrastructure/ExpressLocals.coffee @@ -16,6 +16,15 @@ jsPath = else "/js/" + +imgPath = "/img/" +cssPath = "/stylesheets/" + +if Settings.cdn?.web?.host? + jsPath = "#{Settings.cdn?.web?.host}#{jsPath}" + imgPath = "#{Settings.cdn?.web?.host}#{imgPath}" + cssPath = "#{Settings.cdn?.web?.host}#{cssPath}" + logger.log "Generating file fingerprints..." for path in [ "#{jsPath}libs/require.js", @@ -46,6 +55,8 @@ module.exports = (app, webRouter, apiRouter)-> webRouter.use (req, res, next)-> res.locals.jsPath = jsPath + res.locals.imgPath = imgPath + res.locals.cssPath = cssPath next() webRouter.use (req, res, next)-> diff --git a/services/web/app/views/general/500.jade b/services/web/app/views/general/500.jade index e045a7d457..c6f32ae448 100644 --- a/services/web/app/views/general/500.jade +++ b/services/web/app/views/general/500.jade @@ -3,7 +3,7 @@ html(itemscope, itemtype='http://schema.org/Product') head title Something went wrong link(rel="icon", href="/favicon.ico") - link(rel='stylesheet', href='/stylesheets/style.css') + link(rel='stylesheet', href=cssPath+'/style.css') link(href="//netdna.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css",rel="stylesheet") body .content @@ -12,7 +12,7 @@ html(itemscope, itemtype='http://schema.org/Product') .col-md-8.col-md-offset-2.text-center .page-header h2 Oh dear, something went wrong. - p: img(src="/img/lion-sad-128.png", alt="Sad Lion") + p: img(src=imgPath+"lion-sad-128.png", alt="Sad Lion") p | Something went wrong with your request, sorry. Our staff are probably looking into this, but if it continues, please contact us at #{settings.adminEmail} p diff --git a/services/web/app/views/layout.jade b/services/web/app/views/layout.jade index efe1691df9..f1e4693008 100644 --- a/services/web/app/views/layout.jade +++ b/services/web/app/views/layout.jade @@ -18,7 +18,7 @@ html(itemscope, itemtype='http://schema.org/Product') title= translate(title) + ' - ShareLaTeX, '+translate("online_latex_editor") link(rel="icon", href="/favicon.ico") - link(rel='stylesheet', href='/stylesheets/style.css?fingerprint='+fingerprint('/stylesheets/style.css')) + link(rel='stylesheet', href=cssPath+'/style.css?fingerprint='+fingerprint('/stylesheets/style.css')) if settings.i18n.subdomainLang each subdomainDetails in settings.i18n.subdomainLang diff --git a/services/web/app/views/project/list/side-bar.jade b/services/web/app/views/project/list/side-bar.jade index 11de6e3b14..10f28aa496 100644 --- a/services/web/app/views/project/list/side-bar.jade +++ b/services/web/app/views/project/list/side-bar.jade @@ -135,7 +135,7 @@ p span Get Dropbox Sync p - img(src="/img/dropbox/simple_logo.png") + img(src=imgPath+"dropbox/simple_logo.png") p a(href="/user/subscription/plans", sixpack-convert="left-menu-upgraed-rotation").btn.btn-primary #{translate("upgrade")} p.small.text-centered @@ -148,7 +148,7 @@ p span Get Github Sync p - img(src="/img/github/octocat.jpg") + img(src=imgPath+"github/octocat.jpg") p a(href="/user/subscription/plans", sixpack-convert="left-menu-upgraed-rotation").btn.btn-primary #{translate("upgrade")} p.small.text-centered diff --git a/services/web/app/views/subscriptions/successful_subscription.jade b/services/web/app/views/subscriptions/successful_subscription.jade index 86b0263238..7ed77b6518 100644 --- a/services/web/app/views/subscriptions/successful_subscription.jade +++ b/services/web/app/views/subscriptions/successful_subscription.jade @@ -30,10 +30,10 @@ block content | Henry and James .portraits span.img-circle - img(src="/img/about/henry_oswald.jpg") + img(src=imgPath+"about/henry_oswald.jpg") |   span.img-circle - img(src="/img/about/james_allen.jpg") + img(src=imgPath+"about/james_allen.jpg") p a.btn.btn-primary(href="/project") < #{translate("back_to_your_projects")} diff --git a/services/web/app/views/translations/translation_message.jade b/services/web/app/views/translations/translation_message.jade index 333139139f..cf3ba0ce17 100644 --- a/services/web/app/views/translations/translation_message.jade +++ b/services/web/app/views/translations/translation_message.jade @@ -2,7 +2,7 @@ span(ng-controller="TranslationsPopupController", ng-cloak) .translations-message(ng-hide="hidei18nNotification") a(href=recomendSubdomain.url+currentUrl) !{translate("click_here_to_view_sl_in_lng", {lngName:"" + translate(recomendSubdomain.lngCode) + ""})} - img(src="/img/flags/24/#{recomendSubdomain.lngCode}.png") + img(src=imgPath+"flags/24/#{recomendSubdomain.lngCode}.png") button(ng-click="dismiss()").close.pull-right span(aria-hidden="true") × span.sr-only #{translate("close")} \ No newline at end of file diff --git a/services/web/config/settings.defaults.coffee b/services/web/config/settings.defaults.coffee index e98970fa60..85b12cec56 100644 --- a/services/web/config/settings.defaults.coffee +++ b/services/web/config/settings.defaults.coffee @@ -114,6 +114,10 @@ module.exports = settings = showSocialButtons: false showComments: false + # cdn: + # web: + # host:"https://www.somewhere.com" + # Where your instance of ShareLaTeX can be found publically. Used in emails # that are sent out, generated links, etc. siteUrl : siteUrl = 'http://localhost:3000' From 715ffcfbf251b157183b687d041ea12601673b29 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Mon, 18 Jul 2016 16:24:48 +0100 Subject: [PATCH 2/6] changed ordering on static assets path, just tidying. --- .../infrastructure/ExpressLocals.coffee | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/services/web/app/coffee/infrastructure/ExpressLocals.coffee b/services/web/app/coffee/infrastructure/ExpressLocals.coffee index ce5bf50b87..56de842052 100644 --- a/services/web/app/coffee/infrastructure/ExpressLocals.coffee +++ b/services/web/app/coffee/infrastructure/ExpressLocals.coffee @@ -10,6 +10,10 @@ Modules = require "./Modules" fingerprints = {} Path = require 'path' + + +imgPath = "/img/" +cssPath = "/stylesheets/" jsPath = if Settings.useMinifiedJs "/minjs/" @@ -17,14 +21,6 @@ jsPath = "/js/" -imgPath = "/img/" -cssPath = "/stylesheets/" - -if Settings.cdn?.web?.host? - jsPath = "#{Settings.cdn?.web?.host}#{jsPath}" - imgPath = "#{Settings.cdn?.web?.host}#{imgPath}" - cssPath = "#{Settings.cdn?.web?.host}#{cssPath}" - logger.log "Generating file fingerprints..." for path in [ "#{jsPath}libs/require.js", @@ -46,7 +42,14 @@ for path in [ fingerprints[path] = hash else logger.log filePath:filePath, "file does not exist for fingerprints" - + +logger.log "Finished generating file fingerprints" + +if Settings.cdn?.web?.host? + jsPath = "#{Settings.cdn?.web?.host}#{jsPath}" + imgPath = "#{Settings.cdn?.web?.host}#{imgPath}" + cssPath = "#{Settings.cdn?.web?.host}#{cssPath}" + module.exports = (app, webRouter, apiRouter)-> webRouter.use (req, res, next)-> From a2a8b7123bdfd3bea80a36b5ecddb7706dd3f2a8 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Mon, 18 Jul 2016 17:18:51 +0100 Subject: [PATCH 3/6] created buildCssPath img and js path funcs --- .../infrastructure/ExpressLocals.coffee | 43 +++++++++++++------ services/web/app/views/general/500.jade | 4 +- services/web/app/views/layout.jade | 10 ++--- services/web/app/views/project/editor.jade | 6 ++- .../web/app/views/project/list/side-bar.jade | 4 +- services/web/app/views/sentry.jade | 2 +- .../subscriptions/edit-billing-details.jade | 2 +- .../successful_subscription.jade | 4 +- .../translations/translation_message.jade | 2 +- 9 files changed, 48 insertions(+), 29 deletions(-) diff --git a/services/web/app/coffee/infrastructure/ExpressLocals.coffee b/services/web/app/coffee/infrastructure/ExpressLocals.coffee index 56de842052..0d47855221 100644 --- a/services/web/app/coffee/infrastructure/ExpressLocals.coffee +++ b/services/web/app/coffee/infrastructure/ExpressLocals.coffee @@ -12,8 +12,7 @@ fingerprints = {} Path = require 'path' -imgPath = "/img/" -cssPath = "/stylesheets/" + jsPath = if Settings.useMinifiedJs "/minjs/" @@ -43,12 +42,19 @@ for path in [ 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? - jsPath = "#{Settings.cdn?.web?.host}#{jsPath}" - imgPath = "#{Settings.cdn?.web?.host}#{imgPath}" - cssPath = "#{Settings.cdn?.web?.host}#{cssPath}" + staticFilesBase = Settings.cdn?.web?.host module.exports = (app, webRouter, apiRouter)-> @@ -58,10 +64,26 @@ module.exports = (app, webRouter, apiRouter)-> webRouter.use (req, res, next)-> res.locals.jsPath = jsPath - res.locals.imgPath = imgPath - res.locals.cssPath = cssPath + imgPath = "/img/" + cssPath = "/stylesheets/" + + + res.locals.buildJsPath = (jsFile, fingerprint)-> + if !fingerprint? + fingerprint = getFingerprint(jsPath + jsFile) + p = Path.join(staticFilesBase, jsPath, jsFile) + "?fingerprint=" + fingerprint + + + res.locals.buildCssPath = (cssFile)-> + return Path.join(staticFilesBase, cssPath, cssFile) + "?fingerprint=" + getFingerprint(cssPath + cssFile) + + res.locals.buildImgPath = (imgFile)-> + return Path.join(staticFilesBase, imgPath, imgFile) + next() + + webRouter.use (req, res, next)-> res.locals.settings = Settings next() @@ -127,12 +149,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)-> diff --git a/services/web/app/views/general/500.jade b/services/web/app/views/general/500.jade index c6f32ae448..ef74ed7435 100644 --- a/services/web/app/views/general/500.jade +++ b/services/web/app/views/general/500.jade @@ -3,7 +3,7 @@ html(itemscope, itemtype='http://schema.org/Product') head title Something went wrong link(rel="icon", href="/favicon.ico") - link(rel='stylesheet', href=cssPath+'/style.css') + link(rel='stylesheet', href=buildCssPath('/style.css')) link(href="//netdna.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css",rel="stylesheet") body .content @@ -12,7 +12,7 @@ html(itemscope, itemtype='http://schema.org/Product') .col-md-8.col-md-offset-2.text-center .page-header h2 Oh dear, something went wrong. - p: img(src=imgPath+"lion-sad-128.png", alt="Sad Lion") + p: img(src=buildImgPath("lion-sad-128.png"), alt="Sad Lion") p | Something went wrong with your request, sorry. Our staff are probably looking into this, but if it continues, please contact us at #{settings.adminEmail} p diff --git a/services/web/app/views/layout.jade b/services/web/app/views/layout.jade index f1e4693008..4c5d504a94 100644 --- a/services/web/app/views/layout.jade +++ b/services/web/app/views/layout.jade @@ -15,10 +15,10 @@ html(itemscope, itemtype='http://schema.org/Product') -if (typeof(title) == "undefined") title= 'ShareLaTeX, '+ translate("online_latex_editor") -else - title= translate(title) + ' - ShareLaTeX, '+translate("online_latex_editor") + title= translate(title) + ' - ShareLaTeX, ' + translate("online_latex_editor") link(rel="icon", href="/favicon.ico") - link(rel='stylesheet', href=cssPath+'/style.css?fingerprint='+fingerprint('/stylesheets/style.css')) + link(rel='stylesheet', href=buildCssPath('/style.css')) if settings.i18n.subdomainLang each subdomainDetails in settings.i18n.subdomainLang @@ -124,8 +124,8 @@ html(itemscope, itemtype='http://schema.org/Product') window.csrfToken = "#{csrfToken}"; block scripts - script(src="#{jsPath}libs/jquery-1.11.1.min.js") - script(src="#{jsPath}libs/angular-1.3.15.min.js") + script(src=buildJsPath("libs/jquery-1.11.1.min.js")) + script(src=buildJsPath("libs/angular-1.3.15.min.js")) script. window.sharelatex = { siteUrl: '#{settings.siteUrl}', @@ -196,7 +196,7 @@ html(itemscope, itemtype='http://schema.org/Product') script( data-main=jsPath+'main.js', baseurl=jsPath, - src=jsPath+'libs/require.js?fingerprint='+fingerprint(jsPath + 'libs/require.js') + src=buildJsPath('libs/require.js') ) include contact-us-modal diff --git a/services/web/app/views/project/editor.jade b/services/web/app/views/project/editor.jade index bcb69597eb..1036f95602 100644 --- a/services/web/app/views/project/editor.jade +++ b/services/web/app/views/project/editor.jade @@ -129,7 +129,9 @@ block content - var pdfPath = 'libs/pdfjs-1.3.91/pdf.worker.js' - var fingerprintedPath = fingerprint(jsPath+pdfPath) - - var pdfJsWorkerPath = jsPath+pdfPath+'?fingerprint='+fingerprintedPath + - var pdfJsWorkerPath = buildJsPath(pdfPath, fingerprintedPath) + + script(type='text/javascript'). window.pdfJsWorkerPath = "#{pdfJsWorkerPath}"; @@ -137,7 +139,7 @@ block content data-main=jsPath+"ide.js", baseurl=jsPath, data-ace-base=jsPath+'ace', - src=jsPath+'libs/require.js?fingerprint='+fingerprint(jsPath + 'libs/require.js') + src=buildJsPath('libs/require.js') ) diff --git a/services/web/app/views/project/list/side-bar.jade b/services/web/app/views/project/list/side-bar.jade index 10f28aa496..1045eba4b2 100644 --- a/services/web/app/views/project/list/side-bar.jade +++ b/services/web/app/views/project/list/side-bar.jade @@ -135,7 +135,7 @@ p span Get Dropbox Sync p - img(src=imgPath+"dropbox/simple_logo.png") + img(src=buildImgPath("dropbox/simple_logo.png")) p a(href="/user/subscription/plans", sixpack-convert="left-menu-upgraed-rotation").btn.btn-primary #{translate("upgrade")} p.small.text-centered @@ -148,7 +148,7 @@ p span Get Github Sync p - img(src=imgPath+"github/octocat.jpg") + img(src=buildImgPath("github/octocat.jpg")) p a(href="/user/subscription/plans", sixpack-convert="left-menu-upgraed-rotation").btn.btn-primary #{translate("upgrade")} p.small.text-centered diff --git a/services/web/app/views/sentry.jade b/services/web/app/views/sentry.jade index 9fe5dd3b7d..f339e26cae 100644 --- a/services/web/app/views/sentry.jade +++ b/services/web/app/views/sentry.jade @@ -2,7 +2,7 @@ - if (sentrySrc.match(/^([a-z]+:)?\/\//i)) script(src="#{sentrySrc}") - else - script(src="#{jsPath}libs/#{sentrySrc}") + script(src=buildJsPath("libs/#{sentrySrc}")) - if (typeof(sentrySrc) != "undefined") script(type="text/javascript"). if (typeof(Raven) != "undefined" && Raven.config) { diff --git a/services/web/app/views/subscriptions/edit-billing-details.jade b/services/web/app/views/subscriptions/edit-billing-details.jade index bc47efb4cb..f0b6671bcd 100644 --- a/services/web/app/views/subscriptions/edit-billing-details.jade +++ b/services/web/app/views/subscriptions/edit-billing-details.jade @@ -3,7 +3,7 @@ extends ../layout block content - locals.supressDefaultJs = true script(data-main=jsPath+'main.js', src=jsPath+'libs/require.js', baseurl=jsPath) - script(src=jsPath+'libs/recurly.min.js') + script(src=buildJsPath('libs/recurly.min.js')) .content.content-alt .container diff --git a/services/web/app/views/subscriptions/successful_subscription.jade b/services/web/app/views/subscriptions/successful_subscription.jade index 7ed77b6518..8413f5e036 100644 --- a/services/web/app/views/subscriptions/successful_subscription.jade +++ b/services/web/app/views/subscriptions/successful_subscription.jade @@ -30,10 +30,10 @@ block content | Henry and James .portraits span.img-circle - img(src=imgPath+"about/henry_oswald.jpg") + img(src=buildImgPath("about/henry_oswald.jpg")) |   span.img-circle - img(src=imgPath+"about/james_allen.jpg") + img(src=buildImgPath("about/james_allen.jpg")) p a.btn.btn-primary(href="/project") < #{translate("back_to_your_projects")} diff --git a/services/web/app/views/translations/translation_message.jade b/services/web/app/views/translations/translation_message.jade index cf3ba0ce17..225ad3ea2c 100644 --- a/services/web/app/views/translations/translation_message.jade +++ b/services/web/app/views/translations/translation_message.jade @@ -2,7 +2,7 @@ span(ng-controller="TranslationsPopupController", ng-cloak) .translations-message(ng-hide="hidei18nNotification") a(href=recomendSubdomain.url+currentUrl) !{translate("click_here_to_view_sl_in_lng", {lngName:"" + translate(recomendSubdomain.lngCode) + ""})} - img(src=imgPath+"flags/24/#{recomendSubdomain.lngCode}.png") + img(src=buildImgPath("flags/24/#{recomendSubdomain.lngCode}.png")) button(ng-click="dismiss()").close.pull-right span(aria-hidden="true") × span.sr-only #{translate("close")} \ No newline at end of file From 0cbd9d0ff97d8f860d0e065bdc3da0927f764b3e Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Tue, 19 Jul 2016 11:41:36 +0100 Subject: [PATCH 4/6] use url.resolve to adding https:// part --- .../app/coffee/infrastructure/ExpressLocals.coffee | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/services/web/app/coffee/infrastructure/ExpressLocals.coffee b/services/web/app/coffee/infrastructure/ExpressLocals.coffee index 0d47855221..09ababa54d 100644 --- a/services/web/app/coffee/infrastructure/ExpressLocals.coffee +++ b/services/web/app/coffee/infrastructure/ExpressLocals.coffee @@ -7,12 +7,12 @@ 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/" @@ -71,14 +71,17 @@ module.exports = (app, webRouter, apiRouter)-> res.locals.buildJsPath = (jsFile, fingerprint)-> if !fingerprint? fingerprint = getFingerprint(jsPath + jsFile) - p = Path.join(staticFilesBase, jsPath, jsFile) + "?fingerprint=" + fingerprint + p = Path.join(jsPath, jsFile) + return url.resolve(staticFilesBase, p) + "?fingerprint=" + fingerprint res.locals.buildCssPath = (cssFile)-> - return Path.join(staticFilesBase, cssPath, cssFile) + "?fingerprint=" + getFingerprint(cssPath + cssFile) + p = Path.join(cssPath, cssFile) + return url.resolve(staticFilesBase, p) + "?fingerprint=" + getFingerprint(cssPath + cssFile) res.locals.buildImgPath = (imgFile)-> - return Path.join(staticFilesBase, imgPath, imgFile) + p = Path.join(imgPath, imgFile) + return url.resolve(staticFilesBase, p) next() From f8c38f30a8341e19181bbf666f3592f868be24b8 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Tue, 19 Jul 2016 15:10:07 +0100 Subject: [PATCH 5/6] got build js path working with mathjax --- .../coffee/infrastructure/ExpressLocals.coffee | 16 ++++++++++++---- services/web/app/views/project/editor.jade | 4 ++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/services/web/app/coffee/infrastructure/ExpressLocals.coffee b/services/web/app/coffee/infrastructure/ExpressLocals.coffee index 09ababa54d..b18cbb73f4 100644 --- a/services/web/app/coffee/infrastructure/ExpressLocals.coffee +++ b/services/web/app/coffee/infrastructure/ExpressLocals.coffee @@ -68,11 +68,19 @@ module.exports = (app, webRouter, apiRouter)-> cssPath = "/stylesheets/" - res.locals.buildJsPath = (jsFile, fingerprint)-> - if !fingerprint? - fingerprint = getFingerprint(jsPath + jsFile) + res.locals.buildJsPath = (jsFile, opts = {})-> + if !opts.qs? + opts.qs = {} + if !opts.fingerprint? + opts.fingerprint = getFingerprint(jsPath + jsFile) + else + opts.qs.fingerprint = opts.fingerprint p = Path.join(jsPath, jsFile) - return url.resolve(staticFilesBase, p) + "?fingerprint=" + fingerprint + p = url.resolve(staticFilesBase, p) + qs = querystring.stringify(opts.qs) + if qs? + p = p + "?" + qs + return p res.locals.buildCssPath = (cssFile)-> diff --git a/services/web/app/views/project/editor.jade b/services/web/app/views/project/editor.jade index 1036f95602..75037fb6ed 100644 --- a/services/web/app/views/project/editor.jade +++ b/services/web/app/views/project/editor.jade @@ -100,7 +100,7 @@ block content window.wikiEnabled = #{!!(settings.apis.wiki && settings.apis.wiki.url)}; window.requirejs = { "paths" : { - "mathjax": "/js/libs/mathjax/MathJax.js?config=TeX-AMS_HTML", + "mathjax": "#{buildJsPath('/libs/mathjax/MathJax.js', {qs:{config:'TeX-AMS_HTML'}})}", "moment": "libs/moment-2.7.0", "libs/pdf": "libs/pdfjs-1.3.91/pdf" }, @@ -129,7 +129,7 @@ block content - var pdfPath = 'libs/pdfjs-1.3.91/pdf.worker.js' - var fingerprintedPath = fingerprint(jsPath+pdfPath) - - var pdfJsWorkerPath = buildJsPath(pdfPath, fingerprintedPath) + - var pdfJsWorkerPath = buildJsPath(pdfPath, {fingerprint:fingerprintedPath}) script(type='text/javascript'). From 6c78ab4ace4937caa82c0d85ff5f766c74a4b164 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Wed, 20 Jul 2016 12:58:32 +0100 Subject: [PATCH 6/6] got requirejs working nicely with cdn --- .../infrastructure/ExpressLocals.coffee | 20 ++++++++++++------- services/web/app/views/layout.jade | 8 ++++---- services/web/app/views/project/editor.jade | 9 +++++---- services/web/config/settings.defaults.coffee | 2 +- .../coffee/ide/pdfng/directives/pdfJs.coffee | 11 +--------- services/web/public/stylesheets/style.less | 5 +++++ 6 files changed, 29 insertions(+), 26 deletions(-) diff --git a/services/web/app/coffee/infrastructure/ExpressLocals.coffee b/services/web/app/coffee/infrastructure/ExpressLocals.coffee index b18cbb73f4..b9ee12f365 100644 --- a/services/web/app/coffee/infrastructure/ExpressLocals.coffee +++ b/services/web/app/coffee/infrastructure/ExpressLocals.coffee @@ -64,28 +64,34 @@ 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 = {})-> + p = Path.join(jsPath, jsFile) + doFingerPrint = opts.fingerprint != false + if !opts.qs? opts.qs = {} - if !opts.fingerprint? - opts.fingerprint = getFingerprint(jsPath + jsFile) - else + + if !opts.fingerprint? and doFingerPrint + opts.fingerprint = getFingerprint(p) + else if doFingerPrint opts.qs.fingerprint = opts.fingerprint - p = Path.join(jsPath, jsFile) + p = url.resolve(staticFilesBase, p) qs = querystring.stringify(opts.qs) - if qs? + + if qs? and qs.length > 0 p = p + "?" + qs return p res.locals.buildCssPath = (cssFile)-> p = Path.join(cssPath, cssFile) - return url.resolve(staticFilesBase, p) + "?fingerprint=" + getFingerprint(cssPath + cssFile) + return url.resolve(staticFilesBase, p) + "?fingerprint=" + getFingerprint(p) res.locals.buildImgPath = (imgFile)-> p = Path.join(imgPath, imgFile) diff --git a/services/web/app/views/layout.jade b/services/web/app/views/layout.jade index 4c5d504a94..fd87360125 100644 --- a/services/web/app/views/layout.jade +++ b/services/web/app/views/layout.jade @@ -124,8 +124,8 @@ html(itemscope, itemtype='http://schema.org/Product') window.csrfToken = "#{csrfToken}"; block scripts - script(src=buildJsPath("libs/jquery-1.11.1.min.js")) - script(src=buildJsPath("libs/angular-1.3.15.min.js")) + script(src=buildJsPath("libs/jquery-1.11.1.min.js", {fingerprint:false})) + script(src=buildJsPath("libs/angular-1.3.15.min.js", {fingerprint:false})) script. window.sharelatex = { siteUrl: '#{settings.siteUrl}', @@ -194,8 +194,8 @@ html(itemscope, itemtype='http://schema.org/Product') } }; script( - data-main=jsPath+'main.js', - baseurl=jsPath, + data-main=buildJsPath('main.js'), + baseurl=fullJsPath, src=buildJsPath('libs/require.js') ) diff --git a/services/web/app/views/project/editor.jade b/services/web/app/views/project/editor.jade index 75037fb6ed..c35ae8fbdd 100644 --- a/services/web/app/views/project/editor.jade +++ b/services/web/app/views/project/editor.jade @@ -100,7 +100,7 @@ block content window.wikiEnabled = #{!!(settings.apis.wiki && settings.apis.wiki.url)}; window.requirejs = { "paths" : { - "mathjax": "#{buildJsPath('/libs/mathjax/MathJax.js', {qs:{config:'TeX-AMS_HTML'}})}", + "mathjax": "#{buildJsPath('/libs/mathjax/MathJax.js', {qs:{config:'TeX-AMS_HTML', fingerprint:false}})}", "moment": "libs/moment-2.7.0", "libs/pdf": "libs/pdfjs-1.3.91/pdf" }, @@ -136,10 +136,11 @@ block content window.pdfJsWorkerPath = "#{pdfJsWorkerPath}"; script( - data-main=jsPath+"ide.js", - baseurl=jsPath, - data-ace-base=jsPath+'ace', + data-main=buildJsPath("ide.js"), + baseurl=fullJsPath, + data-ace-base=buildJsPath('ace', {fingerprint:false}), src=buildJsPath('libs/require.js') ) + diff --git a/services/web/config/settings.defaults.coffee b/services/web/config/settings.defaults.coffee index 85b12cec56..e4c565c315 100644 --- a/services/web/config/settings.defaults.coffee +++ b/services/web/config/settings.defaults.coffee @@ -116,7 +116,7 @@ module.exports = settings = # cdn: # web: - # host:"https://www.somewhere.com" + # host:"http://www.sharelatex.dev:3000" # Where your instance of ShareLaTeX can be found publically. Used in emails # that are sent out, generated links, etc. diff --git a/services/web/public/coffee/ide/pdfng/directives/pdfJs.coffee b/services/web/public/coffee/ide/pdfng/directives/pdfJs.coffee index 98361b9ff7..f1c161ffc6 100644 --- a/services/web/public/coffee/ide/pdfng/directives/pdfJs.coffee +++ b/services/web/public/coffee/ide/pdfng/directives/pdfJs.coffee @@ -1,23 +1,14 @@ define [ "base" "ide/pdfng/directives/pdfViewer" - "text!libs/pdfListView/TextLayer.css" - "text!libs/pdfListView/AnnotationsLayer.css" - "text!libs/pdfListView/HighlightsLayer.css" ], ( App pdfViewer - textLayerCss - annotationsLayerCss - highlightsLayerCss + ) -> if PDFJS? PDFJS.workerSrc = window.pdfJsWorkerPath - style = $("