Allow use server.go for testing against local site

Gerrit had 2 different ways to serve files locally:
- start server.go web server
- start gerrit binary with --polygerrit-dev flag

Both implementations did the same handling for local files.

This change removes --polygerrit-dev flag and related java
implementation and instead a new option --dev-cdn is added.
This option enables using cdn for static content.

Change-Id: I40d4c6c048de018bc6d856c889d7ec59592282ed
This commit is contained in:
Dmitrii Filippov
2020-02-11 17:12:14 +01:00
parent b0876e8aa3
commit f363ad89ae
10 changed files with 57 additions and 335 deletions

View File

@@ -64,11 +64,12 @@ func main() {
log.Fatal(err)
}
http.Handle("/", http.FileServer(http.Dir("app")))
http.Handle("/", addDevHeadersMiddleware(http.FileServer(http.Dir("app"))))
http.Handle("/bower_components/",
http.FileServer(httpfs.New(zipfs.New(componentsArchive, "bower_components"))))
addDevHeadersMiddleware(
http.FileServer(httpfs.New(zipfs.New(componentsArchive, "bower_components")))))
http.Handle("/fonts/",
http.FileServer(httpfs.New(zipfs.New(fontsArchive, "fonts"))))
addDevHeadersMiddleware(http.FileServer(httpfs.New(zipfs.New(fontsArchive, "fonts")))))
http.HandleFunc("/index.html", handleIndex)
http.HandleFunc("/changes/", handleProxy)
@@ -92,6 +93,14 @@ func main() {
log.Fatal(http.ListenAndServe(*port, &server{}))
}
func addDevHeadersMiddleware(h http.Handler) http.Handler {
return http.HandlerFunc(func(writer http.ResponseWriter, req *http.Request) {
writer.Header().Set("Access-Control-Allow-Origin", "*")
writer.Header().Set("Cache-Control", "public, max-age=10, must-revalidate")
h.ServeHTTP(writer, req)
})
}
func openDataArchive(path string) (*zip.ReadCloser, error) {
absBinPath, err := resourceBasePath()
if err != nil {