add documentRoot option
This commit is contained in:
parent
022657d53a
commit
99c083a02b
|
@ -12,13 +12,16 @@ class InAppLocalhostServer {
|
||||||
HttpServer? _server;
|
HttpServer? _server;
|
||||||
int _port = 8080;
|
int _port = 8080;
|
||||||
String _directoryIndex = 'index.html';
|
String _directoryIndex = 'index.html';
|
||||||
|
String _documentRoot = './';
|
||||||
|
|
||||||
InAppLocalhostServer({
|
InAppLocalhostServer({
|
||||||
int port = 8080,
|
int port = 8080,
|
||||||
String directoryIndex = 'index.html',
|
String directoryIndex = 'index.html',
|
||||||
|
String documentRoot = './',
|
||||||
}) {
|
}) {
|
||||||
this._port = port;
|
this._port = port;
|
||||||
this._directoryIndex = directoryIndex;
|
this._directoryIndex = directoryIndex;
|
||||||
|
this._documentRoot = (documentRoot.endsWith('/')) ? documentRoot : '$documentRoot/';
|
||||||
}
|
}
|
||||||
|
|
||||||
///Starts the server on `http://localhost:[port]/`.
|
///Starts the server on `http://localhost:[port]/`.
|
||||||
|
@ -52,6 +55,7 @@ class InAppLocalhostServer {
|
||||||
var path = request.requestedUri.path;
|
var path = request.requestedUri.path;
|
||||||
path = (path.startsWith('/')) ? path.substring(1) : path;
|
path = (path.startsWith('/')) ? path.substring(1) : path;
|
||||||
path += (path.endsWith('/')) ? _directoryIndex : '';
|
path += (path.endsWith('/')) ? _directoryIndex : '';
|
||||||
|
path = _documentRoot + path;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
body = (await rootBundle.load(path)).buffer.asUint8List();
|
body = (await rootBundle.load(path)).buffer.asUint8List();
|
||||||
|
|
Loading…
Reference in New Issue