http_server
http_server copied to clipboard
inserting a pathPrefix with relative paths breaks the web server.
Hi, this library really makes writing an http server a lot easier. However, when defining a path, it does not work properly.
Code to reproduce:
import 'dart:io';
import 'package:http_server/http_server.dart';
Future main() async {
var staticFiles = VirtualDirectory('web', pathPrefix: '/app');
staticFiles.allowDirectoryListing = true;
staticFiles.directoryHandler = (dir, request) {
var indexUri = Uri.file(dir.path).resolve('index.html');
staticFiles.serveFile(File(indexUri.toFilePath()), request);
};
var server = await HttpServer.bind(InternetAddress.loopbackIPv4, 8080);
print('Listening on port 8080');
await server.forEach(staticFiles.serveRequest); /*4*/
}
Steps to reproduce:
This is the standard example on the dart website. Insert a pure html file, and it will work. Insert a file that contains relative paths to other files, and it will display an error.
http://localhost:8080/app
Apparently, only the html file will be called correctly, but as it makes another request to the same server, the file will not be found. It is expected that it will look for the file in the VirtualDirectory path, but this does not happen if a pathPrefix is defined. Removing pathPrefix, everything works fine.