7b42bb0e2d
This closes #10513, thanks to @bastelfreak for the report. GET /status/leader returns an IPv6 host with square brackets around the IP address as expected, but the rpcAddr property on the agent model does not. This fixes rpcAddr, updates the Mirage /status/leader mock to properly format an IPv6 host, and changes the agent factory to sometimes produce IPv6 addresses. I added a formatHost utility function to centralise the conditional square bracket-wrapping that would have otherwise been further scattered around.
14 lines
244 B
JavaScript
14 lines
244 B
JavaScript
import isIp from 'is-ip';
|
|
|
|
export default function formatHost(address, port) {
|
|
if (!address || !port) {
|
|
return undefined;
|
|
}
|
|
|
|
if (isIp.v6(address)) {
|
|
return `[${address}]:${port}`;
|
|
} else {
|
|
return `${address}:${port}`;
|
|
}
|
|
}
|