(server: http.Server, protocol: string)
| 105 | * The address might be a URL or it might be a pipe or socket path. |
| 106 | */ |
| 107 | export const ensureAddress = (server: http.Server, protocol: string): URL | string => { |
| 108 | const addr = server.address() |
| 109 | |
| 110 | if (!addr) { |
| 111 | throw new Error("Server has no address") |
| 112 | } |
| 113 | |
| 114 | if (typeof addr !== "string") { |
| 115 | const host = addr.family === "IPv6" ? `[${addr.address}]` : addr.address |
| 116 | return new URL(`${protocol}://${host}:${addr.port}`) |
| 117 | } |
| 118 | |
| 119 | // If this is a string then it is a pipe or Unix socket. |
| 120 | return addr |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Handles the error that occurs in the catch block |
no test coverage detected