Skip to content

Commit

Permalink
Fix webpack chunk loading with STATIC_URL_PREFIX (#11526)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
3 people authored May 20, 2020
1 parent c7c6177 commit b797b76
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions web_src/js/publicpath.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// This sets up webpack's chunk loading to load resources from the 'public'
// directory. 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;

const url = new URL(document.currentScript.src);
__webpack_public_path__ = url.pathname.replace(/\/[^/]*?\/[^/]*?$/, '/');
if (StaticUrlPrefix) {
__webpack_public_path__ = StaticUrlPrefix.endsWith('/') ? StaticUrlPrefix : `${StaticUrlPrefix}/`;
} else {
const url = new URL(document.currentScript.src);
__webpack_public_path__ = url.pathname.replace(/\/[^/]*?\/[^/]*?$/, '/');
}

0 comments on commit b797b76

Please sign in to comment.