getServerUri function

Uri getServerUri(
  1. HttpServer server
)

Implementation

Uri getServerUri(HttpServer server) {
  if (server.address.isLoopback) {
    return Uri(scheme: 'http', host: 'localhost', port: server.port);
  }
  // IPv6 addresses in URLs need to be enclosed in square brackets to avoid
  // URL ambiguity with the ":" in the address.
  if (server.address.type == InternetAddressType.IPv6) {
    return Uri(
      scheme: 'http',
      host: '[${server.address.address}]',
      port: server.port,
    );
  }

  return Uri(scheme: 'http', host: server.address.address, port: server.port);
}