[flutter_tools] support any as a special web-hostname (#54715)

This commit is contained in:
Jonah Williams
2020-04-15 10:55:01 -07:00
committed by GitHub
parent 2f23476cbb
commit c141a53f9a
3 changed files with 63 additions and 5 deletions

View File

@@ -136,7 +136,12 @@ class WebAssetServer implements AssetReader {
DwdsLauncher dwdsLauncher = Dwds.start,
}) async {
try {
final InternetAddress address = (await InternetAddress.lookup(hostname)).first;
InternetAddress address;
if (hostname == 'any') {
address = InternetAddress.anyIPv4;
} else {
address = (await InternetAddress.lookup(hostname)).first;
}
final HttpServer httpServer = await HttpServer.bind(address, port);
final PackageConfig packageConfig = await loadPackageConfigUri(
globals.fs.file(PackageMap.globalPackagesPath).absolute.uri,
@@ -211,6 +216,7 @@ class WebAssetServer implements AssetReader {
final Chrome chrome = await ChromeLauncher.connectedInstance;
return chrome.chromeConnection;
},
hostname: hostname,
urlEncoder: urlTunneller,
enableDebugging: true,
useSseForDebugProxy: useSseForDebugProxy,
@@ -634,7 +640,11 @@ class WebDevFS implements DevFS {
expressionCompiler,
testMode: testMode,
);
_baseUri = Uri.parse('http://$hostname:$port');
if (hostname == 'any') {
_baseUri = Uri.http('localhost:$port', '');
} else {
_baseUri = Uri.http('$hostname:$port', '');
}
return _baseUri;
}

View File

@@ -159,7 +159,11 @@ abstract class FlutterCommand extends Command<void> {
void usesWebOptions({ bool hide = true }) {
argParser.addOption('web-hostname',
defaultsTo: 'localhost',
help: 'The hostname to serve web application on.',
help:
'The hostname that the web sever will use to resolve an IP to serve '
'from. The unresolved hostname is used to launch Chrome when using '
'the chrome Device. The name "any" may also be used to serve on any '
'IPV4 for either the Chrome or web-server device.',
hide: hide,
);
argParser.addOption('web-port',