Skip to content

Commit b797b76

Browse files
silverwindzeripathlafriks
authored
Fix webpack chunk loading with STATIC_URL_PREFIX (#11526)
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]>
1 parent c7c6177 commit b797b76

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

web_src/js/publicpath.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
// This sets up webpack's chunk loading to load resources from the 'public'
2-
// directory. This file must be imported 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;
34

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

0 commit comments

Comments
 (0)