From 022657d53a78e1c700d420197c60476865f84679 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=B5=E3=81=81?= <34892635+fa0311@users.noreply.github.com> Date: Fri, 16 Sep 2022 03:55:52 +0900 Subject: [PATCH 1/2] add directoryIndex option --- lib/src/in_app_localhost_server.dart | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/src/in_app_localhost_server.dart b/lib/src/in_app_localhost_server.dart index 2c7d2c5d..e9df92f2 100755 --- a/lib/src/in_app_localhost_server.dart +++ b/lib/src/in_app_localhost_server.dart @@ -11,9 +11,14 @@ class InAppLocalhostServer { bool _started = false; HttpServer? _server; int _port = 8080; + String _directoryIndex = 'index.html'; - InAppLocalhostServer({int port = 8080}) { + InAppLocalhostServer({ + int port = 8080, + String directoryIndex = 'index.html', + }) { this._port = port; + this._directoryIndex = directoryIndex; } ///Starts the server on `http://localhost:[port]/`. @@ -46,7 +51,7 @@ class InAppLocalhostServer { var path = request.requestedUri.path; path = (path.startsWith('/')) ? path.substring(1) : path; - path += (path.endsWith('/')) ? 'index.html' : ''; + path += (path.endsWith('/')) ? _directoryIndex : ''; try { body = (await rootBundle.load(path)).buffer.asUint8List(); From 99c083a02b7d2e2e9dd063c93718b44ea2e9dad5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=B5=E3=81=81?= <34892635+fa0311@users.noreply.github.com> Date: Fri, 16 Sep 2022 03:57:15 +0900 Subject: [PATCH 2/2] add documentRoot option --- lib/src/in_app_localhost_server.dart | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/src/in_app_localhost_server.dart b/lib/src/in_app_localhost_server.dart index e9df92f2..91acb5bf 100755 --- a/lib/src/in_app_localhost_server.dart +++ b/lib/src/in_app_localhost_server.dart @@ -12,13 +12,16 @@ class InAppLocalhostServer { HttpServer? _server; int _port = 8080; String _directoryIndex = 'index.html'; + String _documentRoot = './'; InAppLocalhostServer({ int port = 8080, String directoryIndex = 'index.html', + String documentRoot = './', }) { this._port = port; this._directoryIndex = directoryIndex; + this._documentRoot = (documentRoot.endsWith('/')) ? documentRoot : '$documentRoot/'; } ///Starts the server on `http://localhost:[port]/`. @@ -52,6 +55,7 @@ class InAppLocalhostServer { var path = request.requestedUri.path; path = (path.startsWith('/')) ? path.substring(1) : path; path += (path.endsWith('/')) ? _directoryIndex : ''; + path = _documentRoot + path; try { body = (await rootBundle.load(path)).buffer.asUint8List();