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
···
router.Get("/favicon.svg", s.Favicon)
router.Get("/favicon.ico", s.Favicon)
router.HandleFunc("/*", func(w http.ResponseWriter, r *http.Request) {
pat := chi.URLParam(r, "*")
if strings.HasPrefix(pat, "did:") || strings.HasPrefix(pat, "@") {
-
s.UserRouter(&middleware).ServeHTTP(w, r)
} else {
// Check if the first path element is a valid handle without '@' or a flattened DID
pathParts := strings.SplitN(pat, "/", 2)
···
return
}
}
-
s.StandardRouter(&middleware).ServeHTTP(w, r)
}
})
···
router.Get("/favicon.svg", s.Favicon)
router.Get("/favicon.ico", s.Favicon)
+
userRouter := s.UserRouter(&middleware)
+
standardRouter := s.StandardRouter(&middleware)
+
router.HandleFunc("/*", func(w http.ResponseWriter, r *http.Request) {
pat := chi.URLParam(r, "*")
if strings.HasPrefix(pat, "did:") || strings.HasPrefix(pat, "@") {
+
userRouter.ServeHTTP(w, r)
} else {
// Check if the first path element is a valid handle without '@' or a flattened DID
pathParts := strings.SplitN(pat, "/", 2)
···
return
}
}
+
standardRouter.ServeHTTP(w, r)
}
})