OverviewFilesCommitsIssuesDocsReleasesPeers

hyper-wallet commits / 2a53692

Fix route matching: Sort routes by length (longest first)
CRITICAL FIX: POST /api/contacts/:id/addresses was matching wrong handler Problem: - Routes checked in definition order using startsWith - 'POST /api/contacts' defined before 'POST /api/contacts/' - URL /api/contacts/123/addresses starts with /api/contacts → matched first route - Called "add new contact" handler instead of "add wallet to contact" - Error: "Missing required fields: address, chain, name" Solution: - Sort routes by path length (longest first) before matching - 'POST /api/contacts/' (18 chars) checked before 'POST /api/contacts' (17 chars) - More specific routes now match first This ensures: - POST /api/contacts/123/addresses → matches 'POST /api/contacts/' ✅ - POST /api/contacts → matches 'POST /api/contacts' ✅ User report: "when trying to add a new wallet i get Missing required fields: address, chain, name" Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2a536923e82ea4a275afd185b47e5a987dc3dba9
by plankatron <fleeky@gmail.com> · 2026-01-27T23:01:57.000Z

Changed files (1) +8 -1

wallet-server.cjs +8 -1
……@@ -1938,7 +1938,14 @@ async function startServer() {
19381938 // Find matching route
19391939 let handled = false
19401940
1941 for (const [routeKey, handler] of Object.entries(routes)) {
1941 // Sort routes by path length (longest first) so specific routes match before generic
1942 const sortedRoutes = Object.entries(routes).sort((a, b) => {
1943 const pathA = a[0].split(' ')[1]
1944 const pathB = b[0].split(' ')[1]
1945 return pathB.length - pathA.length
1946 })
1947
1948 for (const [routeKey, handler] of sortedRoutes) {
19421949 const [method, routePath] = routeKey.split(' ')
19431950
19441951 // Use startsWith for all routes to support path parameters