Avoid loading plugin bundles when running locally

When using run-server.sh (server.go) and you provide a plugins command
line parameter, then the plugin bundle should not be loaded from the
server. So when rewriting the host page let's remove URLs pointing to
polygerrit_assets on the CDN host. Thus loading the bundle will fail
with 404 and normal plugin loading and rewriting kicks in.

Bug: Issue 11274
Change-Id: If62f1d677a11cca2373ae1d45b0d6023f5b35726
This commit is contained in:
Ben Rohlfs 2019-08-14 12:43:24 +02:00
parent c9cf731fcb
commit 4dff051421

View File

@ -43,6 +43,7 @@ var (
host = flag.String("host", "gerrit-review.googlesource.com", "Host to proxy requests to")
scheme = flag.String("scheme", "https", "URL scheme")
cdnPattern = regexp.MustCompile("https://cdn.googlesource.com/polygerrit_ui/[0-9.]*")
bundledPluginsPattern = regexp.MustCompile("https://cdn.googlesource.com/polygerrit_assets/[0-9.]*")
)
func main() {
@ -192,6 +193,9 @@ func rewriteHostPage(reader io.Reader) io.Reader {
// contains window.INITIAL_DATA=...
// Here we rely on the fact that the <script> snippet that we want to append to is the first one.
if len(*plugins) > 0 {
// If the host page contains a reference to a plugin bundle that would be preloaded, then remove it.
replaced = bundledPluginsPattern.ReplaceAllString(replaced, "")
insertionPoint := strings.Index(replaced, "</script>")
builder := new(strings.Builder)
builder.WriteString(