diff options
author | silverwind | 2020-05-29 01:49:38 +0200 |
---|---|---|
committer | GitHub | 2020-05-28 19:49:38 -0400 |
commit | c0c3a533a071d80a0509ea6dd4adf5c10f2ceb48 (patch) | |
tree | f38f446f2ce0eb55b4bc9e6927ce81968fbd3703 | |
parent | ed646078e1fc43bf7bda93c7dd1bdc07e51cac7b (diff) |
Fix webpack chunk loading with STATIC_URL_PREFIX (#11526) (#11544)
Previously, we had only set __webpack_public_path__ to a path which
caused webpack chunks to be loaded from the current origin which is
incorrect when STATIC_URL_PREFIX points to another origin.
This should fix the issue curretnly seen on gitea.com.
Co-authored-by: zeripath <art27@cantab.net>
Co-authored-by: Lauris BH <lauris@nix.lv>
Co-authored-by: zeripath <art27@cantab.net>
Co-authored-by: Lauris BH <lauris@nix.lv>
-rw-r--r-- | templates/base/head.tmpl | 6 | ||||
-rw-r--r-- | web_src/js/publicPath.js | 10 |
2 files changed, 11 insertions, 5 deletions
diff --git a/templates/base/head.tmpl b/templates/base/head.tmpl index f0f388520..6a6a78493 100644 --- a/templates/base/head.tmpl +++ b/templates/base/head.tmpl @@ -84,7 +84,11 @@ for the JavaScript code in this page. */`}} </script> - + <script> + window.config = { + StaticUrlPrefix: '{{StaticUrlPrefix}}' + } + </script> <link rel="shortcut icon" href="{{StaticUrlPrefix}}/img/favicon.png" /> <link rel="mask-icon" href="{{StaticUrlPrefix}}/img/gitea-safari.svg" color="#609926"> <link rel="preload" href="{{StaticUrlPrefix}}/vendor/assets/font-awesome/css/font-awesome.min.css" as="style" onload="this.rel='stylesheet'"> diff --git a/web_src/js/publicPath.js b/web_src/js/publicPath.js index 5d277e442..4c683e175 100644 --- a/web_src/js/publicPath.js +++ b/web_src/js/publicPath.js @@ -1,8 +1,10 @@ -/* This sets up webpack's chunk loading to load resources from the same - directory where it loaded index.js from. This file must be imported - before any lazy-loading is being attempted. */ +// This sets up the URL prefix used in webpack's chunk loading. +// This file must be imported before any lazy-loading is being attempted. +const { StaticUrlPrefix } = window.config; -if (document.currentScript && document.currentScript.src) { +if (StaticUrlPrefix) { + __webpack_public_path__ = StaticUrlPrefix.endsWith('/') ? StaticUrlPrefix : `${StaticUrlPrefix}/`; +} else if (document.currentScript && document.currentScript.src) { const url = new URL(document.currentScript.src); __webpack_public_path__ = `${url.pathname.replace(/\/[^/]*$/, '')}/`; } else { |