From 1fda1f8e90b5a13e84b697564086bcf764767d3d Mon Sep 17 00:00:00 2001 From: a Date: Tue, 25 Oct 2022 22:44:31 -0500 Subject: [PATCH] properly group the middleware to not log the rpcdaemon --- cmd/otter/server.go | 53 ++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/cmd/otter/server.go b/cmd/otter/server.go index 3188a8e..e83bf62 100644 --- a/cmd/otter/server.go +++ b/cmd/otter/server.go @@ -16,33 +16,36 @@ import ( ) func RouteServer(r chi.Router, cfg httpcfg.HttpCfg) { - r.Use(middleware.Logger) - r.Use(middleware.Recoverer) + r.Group(func(r chi.Router) { + r.Use(middleware.Logger) + r.Use(middleware.Recoverer) - // host the apis - r.HandleFunc("/signatures/{hash}", triemap.HttpHandler(sigs.Both)) - r.HandleFunc("/topic0/{hash}", triemap.HttpHandler(topics.Both)) - r.Handle("/chains/{chainId}", http.FileServer(resources.ChainsServer)) - r.Handle("/tokens/{chainId}/{address}/logo.png", http.FileServer(resources.AssetsServer)) - r.HandleFunc("/memstats", func(w http.ResponseWriter, r *http.Request) { - debug.PrintMemStats(false) - }) - r.HandleFunc("/config.json", func(w http.ResponseWriter, r *http.Request) { - json.NewEncoder(w).Encode(map[string]any{ - "erigonURL": cfg.OtsRpcDaemonUrl, - "beaconAPI": cfg.OtsBeaconApiUrl, - "assetsURLPrefix": cfg.OtsAssetUrl, + // host the apis + r.HandleFunc("/signatures/{hash}", triemap.HttpHandler(sigs.Both)) + r.HandleFunc("/topic0/{hash}", triemap.HttpHandler(topics.Both)) + r.Handle("/chains/{chainId}", http.FileServer(resources.ChainsServer)) + r.Handle("/tokens/{chainId}/{address}/logo.png", http.FileServer(resources.AssetsServer)) + r.HandleFunc("/memstats", func(w http.ResponseWriter, r *http.Request) { + debug.PrintMemStats(false) + }) + r.HandleFunc("/config.json", func(w http.ResponseWriter, r *http.Request) { + json.NewEncoder(w).Encode(map[string]any{ + "erigonURL": cfg.OtsRpcDaemonUrl, + "beaconAPI": cfg.OtsBeaconApiUrl, + "assetsURLPrefix": cfg.OtsAssetUrl, + }) + }) + + // host the static site. (dist) + fileServer := http.FileServer(http.Dir(cfg.OtsStaticDir)) + r.Handle("/*", http.StripPrefix("/", fileServer)) + r.Get("/*", func(w http.ResponseWriter, r *http.Request) { + if _, err := os.Stat(cfg.OtsStaticDir + r.RequestURI); os.IsNotExist(err) { + http.StripPrefix(r.RequestURI, fileServer).ServeHTTP(w, r) + } else { + fileServer.ServeHTTP(w, r) + } }) - }) - // host the static site. (dist) - fileServer := http.FileServer(http.Dir(cfg.OtsStaticDir)) - r.Handle("/*", http.StripPrefix("/", fileServer)) - r.Get("/*", func(w http.ResponseWriter, r *http.Request) { - if _, err := os.Stat(cfg.OtsStaticDir + r.RequestURI); os.IsNotExist(err) { - http.StripPrefix(r.RequestURI, fileServer).ServeHTTP(w, r) - } else { - fileServer.ServeHTTP(w, r) - } }) }