forked from tangled.org/core
Monorepo for Tangled — https://tangled.org

appview: initialize routers once

Signed-off-by: oppiliappan <me@oppi.li>

oppi.li 3ac788c5 6c26784d

verified
Changed files
+5 -2
appview
state
+5 -2
appview/state/router.go
··· 35 router.Get("/favicon.svg", s.Favicon) 36 router.Get("/favicon.ico", s.Favicon) 37 38 router.HandleFunc("/*", func(w http.ResponseWriter, r *http.Request) { 39 pat := chi.URLParam(r, "*") 40 if strings.HasPrefix(pat, "did:") || strings.HasPrefix(pat, "@") { 41 - s.UserRouter(&middleware).ServeHTTP(w, r) 42 } else { 43 // Check if the first path element is a valid handle without '@' or a flattened DID 44 pathParts := strings.SplitN(pat, "/", 2) ··· 61 return 62 } 63 } 64 - s.StandardRouter(&middleware).ServeHTTP(w, r) 65 } 66 }) 67
··· 35 router.Get("/favicon.svg", s.Favicon) 36 router.Get("/favicon.ico", s.Favicon) 37 38 + userRouter := s.UserRouter(&middleware) 39 + standardRouter := s.StandardRouter(&middleware) 40 + 41 router.HandleFunc("/*", func(w http.ResponseWriter, r *http.Request) { 42 pat := chi.URLParam(r, "*") 43 if strings.HasPrefix(pat, "did:") || strings.HasPrefix(pat, "@") { 44 + userRouter.ServeHTTP(w, r) 45 } else { 46 // Check if the first path element is a valid handle without '@' or a flattened DID 47 pathParts := strings.SplitN(pat, "/", 2) ··· 64 return 65 } 66 } 67 + standardRouter.ServeHTTP(w, r) 68 } 69 }) 70