Skip to content

Commit

Permalink
[MM-60655] Issue in subpath hosting after changes in root.html (matte…
Browse files Browse the repository at this point in the history
  • Loading branch information
M-ZubairAhmed authored Oct 17, 2024
1 parent c0df35b commit 48cde8c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
14 changes: 7 additions & 7 deletions server/channels/utils/subpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ func updateRootFile(oldRootHTML string, rootHTMLPath string, alreadyRewritten bo
// be updated (and isn't covered by the cases above).
newRootHTML = strings.Replace(newRootHTML, pathToReplace, newPath, -1)

publicPathInWindowsScriptRegex := regexp.MustCompile(`(?s)<script id="publicPathInWindowScript">(.*?)</script>`)

if alreadyRewritten && subpath == "/" {
// Remove the injected script since no longer required. Note that the rewrite above
// will have affected the script, so look for the new subpath, not the old one.
oldScript := getSubpathScript(subpath)
newRootHTML = strings.Replace(newRootHTML, fmt.Sprintf("</style><script>%s</script>", oldScript), "</style>", 1)
// Remove window global publicPath definition if subpath is root
newRootHTML = publicPathInWindowsScriptRegex.ReplaceAllLiteralString(newRootHTML, "<script id=\"publicPathInWindowScript\"></script>")
} else if !alreadyRewritten && subpath != "/" {
// Otherwise, inject the script to define `window.publicPath`.
script := getSubpathScript(subpath)
newRootHTML = strings.Replace(newRootHTML, "</style>", fmt.Sprintf("</style><script>%s</script>", script), 1)
// Inject the script to define `window.publicPath` for the specified subpath
subpathScript := getSubpathScript(subpath)
newRootHTML = publicPathInWindowsScriptRegex.ReplaceAllLiteralString(newRootHTML, fmt.Sprintf("<script id=\"publicPathInWindowScript\">%s</script>", subpathScript))
}

if newRootHTML == oldRootHTML {
Expand Down
Loading

0 comments on commit 48cde8c

Please sign in to comment.