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