Fix server.go for webcomponentsjs-p2

Change-Id: I953677f947c18fac7daa6adbc6a2b50340fd4f06
This commit is contained in:
Tao Zhou
2019-10-18 15:04:21 +02:00
parent b34587f4fc
commit da6e7aabe8

View File

@@ -43,6 +43,8 @@ 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.]*")
webComponentPattern = regexp.MustCompile("webcomponentsjs-p2")
grAppPattern = regexp.MustCompile("gr-app-p2")
bundledPluginsPattern = regexp.MustCompile("https://cdn.googlesource.com/polygerrit_assets/[0-9.]*")
)
@@ -184,9 +186,13 @@ func rewriteHostPage(reader io.Reader) io.Reader {
buf.ReadFrom(reader)
original := buf.String()
// Replace the webcomponentsjs-p2 with webcomponentsjs
replaced := webComponentPattern.ReplaceAllString(original, "webcomponentsjs")
replaced = grAppPattern.ReplaceAllString(replaced, "gr-app")
// Simply remove all CDN references, so files are loaded from the local file system or the proxy
// server instead.
replaced := cdnPattern.ReplaceAllString(original, "")
replaced = cdnPattern.ReplaceAllString(replaced, "")
// Modify window.INITIAL_DATA so that it has the same effect as injectLocalPlugins. To achieve
// this let's add JavaScript lines at the end of the <script>...</script> snippet that also