···
router.HandleFunc("/*", func(w http.ResponseWriter, r *http.Request) {
pat := chi.URLParam(r, "*")
45
-
if strings.HasPrefix(pat, "did:") || strings.HasPrefix(pat, "@") {
46
-
userRouter.ServeHTTP(w, r)
48
-
// Check if the first path element is a valid handle without '@' or a flattened DID
49
-
pathParts := strings.SplitN(pat, "/", 2)
50
-
if len(pathParts) > 0 {
51
-
if userutil.IsHandleNoAt(pathParts[0]) {
52
-
// Redirect to the same path but with '@' prefixed to the handle
53
-
redirectPath := "@" + pat
54
-
http.Redirect(w, r, "/"+redirectPath, http.StatusFound)
56
-
} else if userutil.IsFlattenedDid(pathParts[0]) {
57
-
// Redirect to the unflattened DID version
58
-
unflattenedDid := userutil.UnflattenDid(pathParts[0])
59
-
var redirectPath string
60
-
if len(pathParts) > 1 {
61
-
redirectPath = unflattenedDid + "/" + pathParts[1]
63
-
redirectPath = unflattenedDid
65
-
http.Redirect(w, r, "/"+redirectPath, http.StatusFound)
45
+
pathParts := strings.SplitN(pat, "/", 2)
47
+
if len(pathParts) > 0 {
48
+
firstPart := pathParts[0]
50
+
// if using a DID or handle, just continue as per usual
51
+
if userutil.IsDid(firstPart) || userutil.IsHandle(firstPart) {
52
+
userRouter.ServeHTTP(w, r)
56
+
// if using a flattened DID (like you would in go modules), unflatten
57
+
if userutil.IsFlattenedDid(firstPart) {
58
+
unflattenedDid := userutil.UnflattenDid(firstPart)
59
+
redirectPath := strings.Join(append([]string{unflattenedDid}, pathParts[1:]...), "/")
60
+
http.Redirect(w, r, "/"+redirectPath, http.StatusFound)
64
+
// if using a handle with @, rewrite to work without @
65
+
if normalized := strings.TrimPrefix(firstPart, "@"); userutil.IsHandle(normalized) {
66
+
redirectPath := strings.Join(append([]string{normalized}, pathParts[1:]...), "/")
67
+
http.Redirect(w, r, "/"+redirectPath, http.StatusFound)
69
-
standardRouter.ServeHTTP(w, r)
72
+
standardRouter.ServeHTTP(w, r)