(routes, defaultBackend = null)
| 20 | } |
| 21 | |
| 22 | export function createRouter(routes, defaultBackend = null) { |
| 23 | const sortedRoutes = Object.entries(routes).sort( |
| 24 | ([a], [b]) => b.length - a.length, |
| 25 | ); |
| 26 | |
| 27 | return function route(url) { |
| 28 | for (const [prefix, backend] of sortedRoutes) { |
| 29 | if (matchesPathPrefix(url, prefix)) { |
| 30 | return backend; |
| 31 | } |
| 32 | } |
| 33 | return defaultBackend; |
| 34 | }; |
| 35 | } |
| 36 | |
| 37 | export function isBenignSocketError(err) { |
| 38 | return Boolean(err && BENIGN_SOCKET_ERRORS.has(err.code)); |
no test coverage detected