Add directory listing to server.go
Change-Id: I33a29bec13c559c01c9fa23266376285ee317029
This commit is contained in:
@@ -90,7 +90,13 @@ func main() {
|
||||
}
|
||||
|
||||
redirects := readRedirects()
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) { handleSrcRequest(redirects, w, req) })
|
||||
|
||||
dirListingMux := http.NewServeMux()
|
||||
dirListingMux.Handle("/styles/", http.StripPrefix("/styles/", http.FileServer(http.Dir("app/styles"))))
|
||||
dirListingMux.Handle("/elements/", http.StripPrefix("/elements/", http.FileServer(http.Dir("app/elements"))))
|
||||
dirListingMux.Handle("/behaviors/", http.StripPrefix("/behaviors/", http.FileServer(http.Dir("app/behaviors"))))
|
||||
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) { handleSrcRequest(redirects, dirListingMux, w, req) })
|
||||
|
||||
http.Handle("/fonts/",
|
||||
addDevHeadersMiddleware(http.FileServer(httpfs.New(zipfs.New(fontsArchive, "fonts")))))
|
||||
@@ -167,12 +173,16 @@ func getFinalPath(redirects []redirects, originalPath string) string {
|
||||
return originalPath
|
||||
}
|
||||
|
||||
func handleSrcRequest(redirects []redirects, writer http.ResponseWriter, originalRequest *http.Request) {
|
||||
func handleSrcRequest(redirects []redirects, dirListingMux *http.ServeMux, writer http.ResponseWriter, originalRequest *http.Request) {
|
||||
parsedUrl, err := url.Parse(originalRequest.RequestURI)
|
||||
if err != nil {
|
||||
writer.WriteHeader(500)
|
||||
return
|
||||
}
|
||||
if (parsedUrl.Path != "/" && strings.HasSuffix(parsedUrl.Path, "/")) {
|
||||
dirListingMux.ServeHTTP(writer, originalRequest)
|
||||
return;
|
||||
}
|
||||
if parsedUrl.Path == "/bower_components/web-component-tester/browser.js" {
|
||||
http.Redirect(writer, originalRequest, "/bower_components/wct-browser-legacy/browser.js", 301);
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user