Skip to content

Commit c0c3a53

Browse files
silverwindzeripathlafriks
authored
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 <[email protected]> Co-authored-by: Lauris BH <[email protected]> Co-authored-by: zeripath <[email protected]> Co-authored-by: Lauris BH <[email protected]>
1 parent ed64607 commit c0c3a53

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

templates/base/head.tmpl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@
8484
for the JavaScript code in this page.
8585
*/`}}
8686
</script>
87-
87+
<script>
88+
window.config = {
89+
StaticUrlPrefix: '{{StaticUrlPrefix}}'
90+
}
91+
</script>
8892
<link rel="shortcut icon" href="{{StaticUrlPrefix}}/img/favicon.png" />
8993
<link rel="mask-icon" href="{{StaticUrlPrefix}}/img/gitea-safari.svg" color="#609926">
9094
<link rel="preload" href="{{StaticUrlPrefix}}/vendor/assets/font-awesome/css/font-awesome.min.css" as="style" onload="this.rel='stylesheet'">

web_src/js/publicPath.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
/* This sets up webpack's chunk loading to load resources from the same
2-
directory where it loaded index.js from. This file must be imported
3-
before any lazy-loading is being attempted. */
1+
// This sets up the URL prefix used in webpack's chunk loading.
2+
// This file must be imported before any lazy-loading is being attempted.
3+
const { StaticUrlPrefix } = window.config;
44

5-
if (document.currentScript && document.currentScript.src) {
5+
if (StaticUrlPrefix) {
6+
__webpack_public_path__ = StaticUrlPrefix.endsWith('/') ? StaticUrlPrefix : `${StaticUrlPrefix}/`;
7+
} else if (document.currentScript && document.currentScript.src) {
68
const url = new URL(document.currentScript.src);
79
__webpack_public_path__ = `${url.pathname.replace(/\/[^/]*$/, '')}/`;
810
} else {

0 commit comments

Comments
 (0)