diff --git a/packages/flutter_tools/lib/src/isolated/devfs_web.dart b/packages/flutter_tools/lib/src/isolated/devfs_web.dart index 7ca818befb..f1514e0305 100644 --- a/packages/flutter_tools/lib/src/isolated/devfs_web.dart +++ b/packages/flutter_tools/lib/src/isolated/devfs_web.dart @@ -707,9 +707,9 @@ class WebDevFS implements DevFS { webAssetServer.webRenderer = WebRendererMode.canvaskit; } if (hostname == 'any') { - _baseUri = Uri.http('localhost:$selectedPort', ''); + _baseUri = Uri.http('localhost:$selectedPort', webAssetServer.basePath); } else { - _baseUri = Uri.http('$hostname:$selectedPort', ''); + _baseUri = Uri.http('$hostname:$selectedPort', webAssetServer.basePath); } return _baseUri; } diff --git a/packages/flutter_tools/test/general.shard/web/devfs_web_test.dart b/packages/flutter_tools/test/general.shard/web/devfs_web_test.dart index 2d580b2bdb..348e5d8791 100644 --- a/packages/flutter_tools/test/general.shard/web/devfs_web_test.dart +++ b/packages/flutter_tools/test/general.shard/web/devfs_web_test.dart @@ -1002,6 +1002,62 @@ void main() { ); expect(response.statusCode, 404); })); + + test('DevFS URI includes any specified base path.', () => testbed.run(() async { + final File outputFile = globals.fs.file(globals.fs.path.join('lib', 'main.dart')) + ..createSync(recursive: true); + const String htmlContent = ''; + globals.fs.currentDirectory + .childDirectory('web') + .childFile('index.html') + ..createSync(recursive: true) + ..writeAsStringSync(htmlContent); + outputFile.parent.childFile('a.sources').writeAsStringSync(''); + outputFile.parent.childFile('a.json').writeAsStringSync('{}'); + outputFile.parent.childFile('a.map').writeAsStringSync('{}'); + outputFile.parent.childFile('a.metadata').writeAsStringSync('{}'); + + final ResidentCompiler residentCompiler = MockResidentCompiler(); + when(residentCompiler.recompile( + any, + any, + outputPath: anyNamed('outputPath'), + packageConfig: anyNamed('packageConfig'), + )).thenAnswer((Invocation invocation) async { + return const CompilerOutput('a', 0, []); + }); + + final WebDevFS webDevFS = WebDevFS( + hostname: 'localhost', + port: 0, + packagesFilePath: '.packages', + urlTunneller: null, + useSseForDebugProxy: true, + useSseForDebugBackend: true, + nullAssertions: true, + nativeNullAssertions: true, + buildInfo: BuildInfo.debug, + enableDwds: false, + entrypoint: Uri.base, + testMode: true, + expressionCompiler: null, + chromiumLauncher: null, + nullSafetyMode: NullSafetyMode.unsound, + ); + webDevFS.requireJS.createSync(recursive: true); + webDevFS.stackTraceMapper.createSync(recursive: true); + + final Uri uri = await webDevFS.create(); + + // served on localhost + expect(uri.host, 'localhost'); + // Matches base URI specified in html. + expect(uri.path, '/foo'); + + await webDevFS.destroy(); + }, overrides: { + Artifacts: () => Artifacts.test(), + })); } class MockHttpServer extends Mock implements HttpServer {}