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