···
"github.com/go-chi/chi/v5"
"tangled.org/core/idresolver"
···
r.Route("/{did}", func(r chi.Router) {
82
+
r.Use(h.resolveDidRedirect)
r.Route("/{name}", func(r chi.Router) {
// routes for git operations
r.Get("/info/refs", h.InfoRefs)
···
119
+
func (h *Knot) resolveDidRedirect(next http.Handler) http.Handler {
120
+
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
121
+
didOrHandle := chi.URLParam(r, "did")
122
+
if strings.HasPrefix(didOrHandle, "did:") {
123
+
next.ServeHTTP(w, r)
127
+
trimmed := strings.TrimPrefix(didOrHandle, "@")
128
+
id, err := h.resolver.ResolveIdent(r.Context(), trimmed)
130
+
// invalid did or handle
131
+
h.l.Error("failed to resolve did/handle", "handle", trimmed, "err", err)
132
+
http.Error(w, fmt.Sprintf("failed to resolve did/handle: %s", trimmed), http.StatusInternalServerError)
136
+
newPath := strings.Replace(r.URL.Path, "/"+didOrHandle, "/"+id.DID.String(), 1)
137
+
http.Redirect(w, r, newPath, http.StatusTemporaryRedirect)
func (h *Knot) configureOwner() error {
cfgOwner := h.c.Server.Owner