mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-29 17:03:43 -05:00
Merge pull request #2437 from overleaf/revert-2436-revert-2408-as-dynamic-public-path
Undo revert of Fetch dynamically fetched scripts from CDN GitOrigin-RevId: e317f0e32bbf5da4badf74440622637a54ef5477
This commit is contained in:
parent
2cb158340d
commit
40d274092a
4 changed files with 28 additions and 22 deletions
|
@ -77,6 +77,12 @@ module.exports = function(webRouter, privateApiRouter, publicApiRouter) {
|
||||||
staticFilesBase = ''
|
staticFilesBase = ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
res.locals.buildBaseAssetPath = function() {
|
||||||
|
// Return the base asset path (including the CDN url) so that webpack can
|
||||||
|
// use this to dynamically fetch scripts (e.g. PDFjs worker)
|
||||||
|
return Url.resolve(staticFilesBase, '/')
|
||||||
|
}
|
||||||
|
|
||||||
res.locals.buildJsPath = function(jsFile) {
|
res.locals.buildJsPath = function(jsFile) {
|
||||||
let path
|
let path
|
||||||
if (IS_DEV_ENV) {
|
if (IS_DEV_ENV) {
|
||||||
|
@ -88,7 +94,7 @@ module.exports = function(webRouter, privateApiRouter, publicApiRouter) {
|
||||||
// In production: resolve path from webpack manifest file
|
// In production: resolve path from webpack manifest file
|
||||||
// We are guaranteed to have a manifest file since webpack compiles in
|
// We are guaranteed to have a manifest file since webpack compiles in
|
||||||
// the build
|
// the build
|
||||||
path = webpackManifest[jsFile]
|
path = `/${webpackManifest[jsFile]}`
|
||||||
}
|
}
|
||||||
|
|
||||||
return Url.resolve(staticFilesBase, path)
|
return Url.resolve(staticFilesBase, path)
|
||||||
|
@ -96,7 +102,7 @@ module.exports = function(webRouter, privateApiRouter, publicApiRouter) {
|
||||||
|
|
||||||
// Temporary hack while jQuery/Angular dependencies are *not* bundled,
|
// Temporary hack while jQuery/Angular dependencies are *not* bundled,
|
||||||
// instead copied into output directory
|
// instead copied into output directory
|
||||||
res.locals.buildCopiedJsAssetPath = function(jsFile, opts = {}) {
|
res.locals.buildCopiedJsAssetPath = function(jsFile) {
|
||||||
let path
|
let path
|
||||||
if (IS_DEV_ENV) {
|
if (IS_DEV_ENV) {
|
||||||
// In dev: resolve path to root directory
|
// In dev: resolve path to root directory
|
||||||
|
@ -107,27 +113,17 @@ module.exports = function(webRouter, privateApiRouter, publicApiRouter) {
|
||||||
// In production: resolve path from webpack manifest file
|
// In production: resolve path from webpack manifest file
|
||||||
// We are guaranteed to have a manifest file since webpack compiles in
|
// We are guaranteed to have a manifest file since webpack compiles in
|
||||||
// the build
|
// the build
|
||||||
path = webpackManifest[jsFile]
|
path = `/${webpackManifest[jsFile]}`
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts.cdn !== false) {
|
return Url.resolve(staticFilesBase, path)
|
||||||
path = Url.resolve(staticFilesBase, path)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts.qs) {
|
res.locals.mathJaxPath = `/js/libs/mathjax/MathJax.js?${querystring.stringify(
|
||||||
path = path + '?' + querystring.stringify(opts.qs)
|
|
||||||
}
|
|
||||||
|
|
||||||
return path
|
|
||||||
}
|
|
||||||
|
|
||||||
res.locals.mathJaxPath = res.locals.buildCopiedJsAssetPath(
|
|
||||||
'js/libs/mathjax/MathJax.js',
|
|
||||||
{
|
{
|
||||||
cdn: false,
|
config: 'TeX-AMS_HTML,Safe'
|
||||||
qs: { config: 'TeX-AMS_HTML,Safe' }
|
|
||||||
}
|
}
|
||||||
)
|
)}`
|
||||||
|
|
||||||
res.locals.lib = PackageVersions.lib
|
res.locals.lib = PackageVersions.lib
|
||||||
|
|
||||||
|
@ -168,7 +164,7 @@ module.exports = function(webRouter, privateApiRouter, publicApiRouter) {
|
||||||
// In production: resolve path from webpack manifest file
|
// In production: resolve path from webpack manifest file
|
||||||
// We are guaranteed to have a manifest file since webpack compiles in
|
// We are guaranteed to have a manifest file since webpack compiles in
|
||||||
// the build
|
// the build
|
||||||
path = webpackManifest[cssFileName]
|
path = `/${webpackManifest[cssFileName]}`
|
||||||
}
|
}
|
||||||
|
|
||||||
return Url.resolve(staticFilesBase, path)
|
return Url.resolve(staticFilesBase, path)
|
||||||
|
|
|
@ -47,6 +47,9 @@ html(
|
||||||
|
|
||||||
script(type="text/javascript").
|
script(type="text/javascript").
|
||||||
window.csrfToken = "#{csrfToken}";
|
window.csrfToken = "#{csrfToken}";
|
||||||
|
//- Configure dynamically loaded assets (via webpack) to be downloaded from CDN
|
||||||
|
//- See: https://webpack.js.org/guides/public-path/#on-the-fly
|
||||||
|
window.baseAssetPath = "#{buildBaseAssetPath()}"
|
||||||
|
|
||||||
script(src=buildCopiedJsAssetPath('js/libs/jquery-1.11.1.min.js'))
|
script(src=buildCopiedJsAssetPath('js/libs/jquery-1.11.1.min.js'))
|
||||||
script(type="text/javascript").
|
script(type="text/javascript").
|
||||||
|
|
|
@ -14,6 +14,11 @@
|
||||||
* DS207: Consider shorter variations of null checks
|
* DS207: Consider shorter variations of null checks
|
||||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// Configure dynamically loaded assets (via webpack) to be downloaded from CDN
|
||||||
|
// See: https://webpack.js.org/guides/public-path/#on-the-fly
|
||||||
|
__webpack_public_path__ = window.baseAssetPath
|
||||||
|
|
||||||
define([
|
define([
|
||||||
'libraries',
|
'libraries',
|
||||||
'libs/polyfills/symbol',
|
'libs/polyfills/symbol',
|
||||||
|
|
|
@ -41,9 +41,6 @@ module.exports = {
|
||||||
output: {
|
output: {
|
||||||
path: path.join(__dirname, '/public'),
|
path: path.join(__dirname, '/public'),
|
||||||
|
|
||||||
// Serve from the root of public directory
|
|
||||||
publicPath: '/',
|
|
||||||
|
|
||||||
// By default write into js directory
|
// By default write into js directory
|
||||||
filename: 'js/[name].js',
|
filename: 'js/[name].js',
|
||||||
|
|
||||||
|
@ -82,7 +79,12 @@ module.exports = {
|
||||||
options: {
|
options: {
|
||||||
// Write into js directory (note: customising this is not possible
|
// Write into js directory (note: customising this is not possible
|
||||||
// with pdfjs-dist/webpack auto loader)
|
// with pdfjs-dist/webpack auto loader)
|
||||||
name: 'js/pdfjs-worker.[hash].js'
|
name: 'js/pdfjs-worker.[hash].js',
|
||||||
|
// Override dynamically-set publicPath to explicitly use root.
|
||||||
|
// This prevents a security problem where the Worker - normally
|
||||||
|
// loaded from a CDN - has cross-origin issues, by forcing it to not
|
||||||
|
// be loaded from the CDN
|
||||||
|
publicPath: '/'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in a new issue