I have a simple Dart HTTPServer running which serves requests by virDir.serveRequest(request);
which works for the URL 192.168.1.200:8080/index.html
but serves a 404 Not Found
if I use 192.168.1.200:8080
or 192.168.1.200:8080/
. I, probably naively, though that the default was automatic. BTW this is all new to me.
I didn't notice any default settings in HTMLServer, how is this accomplished?
(edit)
I've been able to detect the use using the default and compute the correct file name but don't understand how to deliver it to the browser:
_processRequest(newPath, request) { // new path is index.html
File file = new File(newPath);
file.exists().then((found) {
if(found) {
file.openRead().pipe(request.response); // probably dies here
}
else {
_send404(request.response);
}
});
}
[edit]
Still unable to serve the index.html file. I've tried using VirtualDirector.serveFile() but can't make it work when I try to handle the default index.html file. I've been attempting to follow an example.
final HTTP_ROOT_PATH = Platform.script.resolve('../web').toFilePath();
final virDir = new VirtualDirectory(HTTP_ROOT_PATH)
..jailRoot = false // process links will work
..followLinks = true
..allowDirectoryListing = true;
var dir = new Directory(virDir.root);
var indexUri = new Uri.file(dir.path).resolve('/index.html');
virDir.serveFile(new File(indexUri.toFilePath()), request);
When I run this and print indexUri.toFilePath() the output is '/index.html'
My code is in /srv/fireimager/bin and /srv/fireimager/web with the latter the virtual directory root. When I detect that the user has not specified /index.html in the url it doesn't work, there's no error emitted, and the javascript console shows nothing so nothing is served to the browser.
I obviously don't understand how to use VirtualDirectly.serveFiler.