| … | … | @@ -1941,15 +1941,14 @@ async function startServer() { |
| 1941 | 1941 | for (const [routeKey, handler] of Object.entries(routes)) { |
| 1942 | 1942 | const [method, routePath] = routeKey.split(' ') |
| 1943 | 1943 | |
| 1944 | | // For POST routes, match exactly; for GET routes with params, use startsWith |
| 1945 | | const isMatch = (method === 'POST') |
| 1946 | | ? (req.method === method && req.url === routePath) |
| 1947 | | : (req.method === method && req.url.startsWith(routePath)) |
| 1944 | // Use startsWith for all routes to support path parameters |
| 1945 | const isMatch = req.method === method && req.url.startsWith(routePath) |
| 1948 | 1946 | |
| 1949 | 1947 | if (isMatch) { |
| 1950 | | // Extract parameter (e.g., chain from /api/balance/bitcoin) |
| 1948 | // Extract parameters (e.g., :id/addresses from /api/contacts/:id/addresses) |
| 1951 | 1949 | const param = req.url.substring(routePath.length) |
| 1952 | | await handler(req, res, param) |
| 1950 | const params = param ? param.split('/').filter(p => p) : [] |
| 1951 | await handler(req, res, ...params) |
| 1953 | 1952 | handled = true |
| 1954 | 1953 | break |
| 1955 | 1954 | } |